<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Fonaments de Slackware Linux</title>
<link rel="stylesheet" type="text/css" href="default.css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div lang="en" class="book">
<div class="titlepage">
<div>
<div><h1 class="title">
<a name="idm951885612"></a>Fonaments de Slackware Linux</h1></div>
<div><h2 class="subtitle">Corresponents a Slackware Linux 12.0</h2></div>
<div><div class="authorgroup">
      <div class="author"><h3 class="author">Daniël de Kok</h3></div>
    </div></div>
<div><p class="copyright">Copyright © 2002-2009 Daniël de Kok</p></div>
<div><div class="legalnotice">
<a name="idm951879644"></a>
      <p class="legalnotice-title"><b>LLicència</b></p>

      <p>
        Alguns drets reservats. Este llibre està disponible baix la Creative Commons
        Attribution 3.0 License (CC-BY). Esta llicència està disponible a:
        <a class="ulink" href="http://creativecommons.org/licenses/by/3.0/" target="_top">http://creativecommons.org/licenses/by/3.0/</a>
      </p>

      <p>
	Linux és una marca registrada de Linus Torvalds. Slackware
	Linux és una marca registrada de Patrick Volkerding i
	Slackware Linux, Inc.  UNIX és una marca registrada de The
	Open Group.
      </p>
    </div></div>
<div><p class="pubdate">Thu Sep 27 10:20:04 CEST 2007</p></div>
</div>
<hr>
</div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="preface"><a href="#preface">Preface</a></span></dt>
<dt><span class="part"><a href="#getstarted">I. Per començar ??Getting started??</a></span></dt>
<dd><dl>
<dt><span class="chapter"><a href="#chap-book">1. Quan a este llibre</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-book-availability">1.1. Disponibilitat</a></span></dt>
<dt><span class="sect1"><a href="#chap-book-conventions">1.2. Convencions</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-intro">2. Introducció a Slackware Linux</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-intro-linux">2.1. Què és Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-gnulinux">2.2. Qu és GNU/Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-slackware">2.3. Què és Slackware Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-unix">2.4. La filosofia UNIX</a></span></dt>
<dt><span class="sect1"><a href="#free-software">2.5. Programar lliure i de font oberta</a></span></dt>
<dt><span class="sect1"><a href="#slackware-features">2.6. Característiques de Slackware Linux 12.0</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-getting">2.7. Com aconseguir Slackware Linux (Getting Slackware Linux)</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-help">3. Fonts d'ajuda </a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-help-system">3.1. Al teu sistema</a></span></dt>
<dt><span class="sect1"><a href="#chap-help-internet">3.2. A la Internet</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#concepts">4. Conceptes generals</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#concepts-multitasca">4.1. Multitasca</a></span></dt>
<dt><span class="sect1"><a href="#concepts-fshierarchy">4.2. Jerarquia del sistema de fitxers </a></span></dt>
<dt><span class="sect1"><a href="#concepts-devices">4.3. Dispositius</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-install">5. La instal·lació de Slackware Linux </a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-install-bootcd">5.1. Llançar el CD d'instal·lació </a></span></dt>
<dt><span class="sect1"><a href="#chap-install-partitioning">5.2. Particionar un disc dur </a></span></dt>
<dt><span class="sect1"><a href="#chap-install-installing">5.3. Instal·lant Slackware Linux</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#getstarted-custominstall">6. Custom installation</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#getstarted-custominstall-partition">6.1. Partitioning a hard disk</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-initfs">6.2. Initializing and mounting filesystems</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-packages">6.3. Installing packages</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-config">6.4. Post-install configuration</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-script">6.5. Automated installation script</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="part"><a href="#basics">II. Conceptes fonamentals de Slackware Linux</a></span></dt>
<dd><dl>
<dt><span class="chapter"><a href="#chap-shell">7. El shell</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-shell-intro">7.1. Introducció </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-executing">7.2. Executant ordres </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-moving">7.3. Anant amunt i avall </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-history">7.4. Historial d'ordres </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-completion">7.5. Autocompletat</a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-wildcards">7.6. Comodins </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-inout">7.7. Redireccions i canonades </a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-filesystem">8. Files and directories</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-filesystem-introduction">8.1. Some theory</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystems-analyzing">8.2. Analyzing files</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-directories">8.3. Working with directories</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-managing">8.4. Managing files and directories</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-permissions">8.5. Permissions</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-finding">8.6. Finding files</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-archives">8.7. Archives</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-mounting">8.8. Mounting filesystems</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-gnupg">8.9. Encrypting and signing files</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-textproc">9. Text processing</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-textproc-simple">9.1. Simple text manipulation</a></span></dt>
<dt><span class="sect1"><a href="#chap-textproc-regexps">9.2. Regular expressions</a></span></dt>
<dt><span class="sect1"><a href="#chap-textproc-grep">9.3. grep</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-procmgmt">10. Process management</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-procmgmt-theory">10.1. Theory</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-analyzing">10.2. Analyzing running processes</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-managing">10.3. Managing processes</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-jobcontrol">10.4. Job control</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="part"><a href="#editing">III. Editant i formatant text ??"typesetting"??</a></span></dt>
<dd><dl>
<dt><span class="chapter"><a href="#editing-latex">11. LaTeX</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#editing-latex-introduction">11.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#editing-latex-basic">11.2. Preparing basic LaTeX documents</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="part"><a href="#email">IV. Correu electrònic</a></span></dt>
<dd><dl>
<dt><span class="chapter"><a href="#email-mutt">12. Reading and writing e-mail with mutt</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#email-mutt-introduction">12.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-usage">12.2. Usage</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-basicsetup">12.3. Basic setup</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-imap">12.4. Using IMAP</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-gnupg">12.5. Signing/encrypting e-mails</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#email-sendmail">13. Sendmail</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#email-sendmail-introduction">13.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#email-sendmail-installation">13.2. Installation</a></span></dt>
<dt><span class="sect1"><a href="#email-sendmail-configuration">13.3. Configuration</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="part"><a href="#sysadmin">V. Administració del sistema</a></span></dt>
<dd><dl>
<dt><span class="chapter"><a href="#chap-usermgmt">14. Gestió d'usuaris </a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-usermgmt-intro">14.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-user">14.2. Afegint i suprimint usuaris</a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-su">14.3. Evitant l'ús de root mitjançant su </a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-quota">14.4. Cuota de disc</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#printing">15. Configuració de impressores </a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#printing-intro">15.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#printing-preparations">15.2. Preparatius </a></span></dt>
<dt><span class="sect1"><a href="#printing-configuration">15.3. Configuració</a></span></dt>
<dt><span class="sect1"><a href="#printing-accesscontrol">15.4. Control d'accés </a></span></dt>
<dt><span class="sect1"><a href="#printing-gspapersize">15.5. Tamany del paper Ghostscript </a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-x11">16. X11</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-x11-config">16.1. Configuració d'X</a></span></dt>
<dt><span class="sect1"><a href="#chap-x11-wm">16.2. Gestor de finestres </a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-pkgmgmt">17. Gestió de paquets</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-pkgmgmt-pkgtools">17.1. Pkgtools</a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-slackpkg">17.2. Slackpkg</a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-rsync">17.3. Obtenint actualitzacions mitjançant rsync 
    </a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-tagfiles">17.4. Tagfiles (fitxers d'etiquetes)</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#kernel">18. Contruïnt un núcli</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-kernel-intro">18.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-build">18.2. Configuració</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-compile">18.3. La compilació</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-install">18.4. Instal·lació</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-init">19. System initialization</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-init-lilo">19.1. The bootloader</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-init">19.2. init</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-initscripts">19.3. Initialization scripts</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-udev">19.4. Hotplugging and device node management</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-firmware">19.5. Device firmware</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#idm950258444">20. Security</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950258188">20.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950256916">20.2. Closing services</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#sysadmin-misc">21. Miscel·lània</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#sysadmin-misc-cron">21.1. Planificant tasques amb cron </a></span></dt>
<dt><span class="sect1"><a href="#sysadmin-misc-hdparm">21.2. Paràmetres de disc dur </a></span></dt>
<dt><span class="sect1"><a href="#sysadmin-memory-hdparm">21.3. Monitorejant  l'ús de la memòria </a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="part"><a href="#netadmin">VI. Administració de xarxa</a></span></dt>
<dd><dl>
<dt><span class="chapter"><a href="#sysadmin-netconfig">22. Networking configuration</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#sysadmin-netconfig-hardware">22.1. Hardware</a></span></dt>
<dt><span class="sect1"><a href="#idm950197876">22.2. Configuration of interfaces</a></span></dt>
<dt><span class="sect1"><a href="#idm950191964">22.3. Configuration of interfaces (IPv6)</a></span></dt>
<dt><span class="sect1"><a href="#idm950179556">22.4. Wireless interfaces</a></span></dt>
<dt><span class="sect1"><a href="#idm950179492">22.5. Resolving</a></span></dt>
<dt><span class="sect1"><a href="#idm950170580">22.6. IPv4 Forwarding</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#ipsec">23. IPsec</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950156644">23.1. Theory</a></span></dt>
<dt><span class="sect1"><a href="#idm950151132">23.2. Linux configuration</a></span></dt>
<dt><span class="sect1"><a href="#idm950147732">23.3. Installing IPsec-Tools</a></span></dt>
<dt><span class="sect1"><a href="#idm950142780">23.4. Setting up IPsec with manual keying</a></span></dt>
<dt><span class="sect1"><a href="#idm950129420">23.5. Setting up IPsec with automatic key exchanging</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#idm950106380">24. The Internet super server</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950106060">24.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950104412">24.2. Configuration</a></span></dt>
<dt><span class="sect1"><a href="#idm950098324">24.3. TCP wrappers</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#idm950091836">25. Apache</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950091548">25.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950090932">25.2. Installation</a></span></dt>
<dt><span class="sect1"><a href="#idm950085940">25.3. User directories</a></span></dt>
<dt><span class="sect1"><a href="#idm950083380">25.4. Virtual hosts</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#idm950077628">26. BIND</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950077340">26.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950069932">26.2. Making a caching nameserver</a></span></dt>
</dl></dd>
</dl></dd>
</dl>
</div>
<div class="list-of-figures">
<p><b>List of Figures</b></p>
<dl>
<dt>4.1. <a href="#fork">Bifurcant un procés (forking)</a>
</dt>
<dt>4.2. <a href="#filesystem-structure">La estructura del sistema de fitxers </a>
</dt>
<dt>5.1. <a href="#chap-install-partitioning-cfdisk">La eina de particionat cfdisk</a>
</dt>
<dt>5.2. <a href="#chap-install-installing-setup">La eina setup </a>
</dt>
<dt>5.3. <a href="#chap-install-installing-addswap">Preparant la partició d'intercanvi </a>
</dt>
<dt>5.4. <a href="#chap-install-installing-partselect">Seleccionant una partició a inicialitzar </a>
</dt>
<dt>5.5. <a href="#chap-install-installing-fscheck">Formatant la partició </a>
</dt>
<dt>5.6. <a href="#chap-install-installing-filesystem">Triant el tipus de sistema de fitxers </a>
</dt>
<dt>5.7. <a href="#chap-install-installing-medium">Triant el medi origen </a>
</dt>
<dt>5.8. <a href="#chap-install-installing-disksets">Triant els conjunts de discs</a>
</dt>
<dt>5.9. <a href="#chap-install-installing-installkernel">Instal·lant el núcli</a>
</dt>
<dt>5.10. <a href="#chap-install-installing-bootdisk">Creant un disc d'arranc </a>
</dt>
<dt>5.11. <a href="#chap-install-installing-modem">Seleccionant el modem per defecte </a>
</dt>
<dt>5.12. <a href="#chap-install-installing-hotplug">Habilitant l'endollat en calent</a>
</dt>
<dt>5.13. <a href="#chap-install-installing-liloinstall">Triant el tipus d'instal·lació de LILO </a>
</dt>
<dt>5.14. <a href="#chap-install-installing-framebuffer">Triant la resolució framebuffer </a>
</dt>
<dt>5.15. <a href="#chap-install-installing-kernel-param">Afegint paràmetres al núcli</a>
</dt>
<dt>5.16. <a href="#chap-install-installing-lilo-dest">Escollint on s'hauria d'instal·lar el LILO </a>
</dt>
<dt>5.17. <a href="#chap-install-installing-mouse">Configurant un ratolí </a>
</dt>
<dt>5.18. <a href="#chap-install-installing-ask-load-gpm">Escollint si GPM s'hauria d'iniciar</a>
</dt>
<dt>5.19. <a href="#chap-install-installing-ask-configure-network">Escollint si t'agradaria configurar la connectivatat de xarxa
      </a>
</dt>
<dt>5.20. <a href="#chap-install-installing-hostname">Posant el nom de host </a>
</dt>
<dt>5.21. <a href="#chap-install-installing-domainname">Posant el nom de domini </a>
</dt>
<dt>5.22. <a href="#chap-install-installing-set-ipconfig-type">Configuració manual o automàtica de l'adreça IP
      </a>
</dt>
<dt>5.23. <a href="#chap-install-installing-ipaddr">Posant l'adreça IP</a>
</dt>
<dt>5.24. <a href="#chap-install-installing-netmask">Posant la màscara de subxarxa</a>
</dt>
<dt>5.25. <a href="#chap-install-installing-gateway">Posant la porta d'enllaç</a>
</dt>
<dt>5.26. <a href="#chap-install-installing-ask-nameserver">Triant si vols emprar un servidor de noms o no 
      </a>
</dt>
<dt>5.27. <a href="#chap-install-installing-nameserver">Posant el(s) servidor(s) de noms</a>
</dt>
<dt>5.28. <a href="#chap-install-installing-network-confirm">Confirmant els paràmetres de xarxa </a>
</dt>
<dt>5.29. <a href="#chap-install-installing-startup-services">Habilitant/deshabilitant serveis d'inici </a>
</dt>
<dt>5.30. <a href="#chap-install-installing-ask-clock-utc">Triant si el rellotge del sistema es posa UTC 
      </a>
</dt>
<dt>5.31. <a href="#chap-install-installing-timezone">Posnat la zona horària </a>
</dt>
<dt>5.32. <a href="#chap-install-installing-defaultwm">Escollint el gestor de finestres per defecte 
      </a>
</dt>
<dt>5.33. <a href="#chap-install-installing-rootpasswd">Posant la contrasenya de root</a>
</dt>
<dt>5.34. <a href="#chap-install-installing-finished">Finalitzat</a>
</dt>
<dt>7.1. <a href="#fig-shell-inout">Entrada i eixida estàndar </a>
</dt>
<dt>7.2. <a href="#fig-shell-pipeline">Una conducció </a>
</dt>
<dt>8.1. <a href="#chap-filesystems-introduction-links-hardlink">The structure of a hard link</a>
</dt>
<dt>8.2. <a href="#chap-filesystems-introduction-links-symlink">The structure of a symbolic link</a>
</dt>
<dt>10.1. <a href="#chap-procmgmt-theory-proc-procstates">Process states</a>
</dt>
<dt>22.1. <a href="#ipv6address">The anatomy of an IPv6 address</a>
</dt>
<dt>22.2. <a href="#router">Router example</a>
</dt>
</dl>
</div>
<div class="list-of-tables">
<p><b>List of Tables</b></p>
<dl>
<dt>5.1. <a href="#chap-install-bootcd-installkernels">Núclis d'instal·lació</a>
</dt>
<dt>7.1. <a href="#chap-shell-moving-char-shortcuts-move">Movent-se per caràcters </a>
</dt>
<dt>7.2. <a href="#chap-shell-moving-char-shortcuts-delete">Esborrant caràcters </a>
</dt>
<dt>7.3. <a href="#chap-shell-moving-char-shortcuts-swap">Intercanviant caràcters </a>
</dt>
<dt>7.4. <a href="#chap-shell-moving-word-shortcuts-move">Movent-se per paraules </a>
</dt>
<dt>7.5. <a href="#chap-shell-moving-word-shortcuts-delete">Eliminar paraules </a>
</dt>
<dt>7.6. <a href="#chap-shell-moving-word-shortcuts-modify">Modificant paraules </a>
</dt>
<dt>7.7. <a href="#chap-shell-moving-line-shortcuts-move">Movent-se per línies</a>
</dt>
<dt>7.8. <a href="#chap-shell-moving-line-shortcuts-delete">Suprimint línies</a>
</dt>
<dt>7.9. <a href="#chap-shell-wildcards-thewildcards">Comodins Bash </a>
</dt>
<dt>8.1. <a href="#chap-filesystem-introduction-atoms-inodes">Common inode fields</a>
</dt>
<dt>8.2. <a href="#chap-filesystem-permissions-numbers">Meaning of numbers in the mode octet</a>
</dt>
<dt>8.3. <a href="#chap-filesystem-analyzing-viewing-less-keys">less command keys</a>
</dt>
<dt>8.4. <a href="#chap-filesystem-permissions-acl-setting-flags">System-specific <span class="command">setfacl</span> flags</a>
</dt>
<dt>8.5. <a href="#chap-filesystem-finding-find-nametype-type-params">Parameters for the '-type' operand</a>
</dt>
<dt>8.6. <a href="#archive-extentions">Archive file extensions</a>
</dt>
<dt>9.1. <a href="#chap-textproc-simple-tr-charclasses">tr character classes</a>
</dt>
<dt>10.1. <a href="#chap-procmgmt-theory-proc-struct">The structure of a process</a>
</dt>
<dt>11.1. <a href="#latex-documentclasses">LaTeX document classes</a>
</dt>
<dt>11.2. <a href="#latex-fontstyles">LaTeX font styles</a>
</dt>
<dt>17.1. <a href="#chap-pkgmgmt-tagfiles-creating-fields">Capms de tagfile</a>
</dt>
<dt>22.1. <a href="#idm950187636">Important IPv6 Prefixes</a>
</dt>
<dt>26.1. <a href="#idm950073244">DNS records</a>
</dt>
</dl>
</div>

  

  

  <div lang="en" class="preface">
<div class="titlepage"><div><div><h1 class="title">
<a name="preface"></a>Preface</h1></div></div></div>
  

  <p>
    This book aims to provide an introduction to Slackware Linux. It
    addresses people who have little or no GNU/Linux experience, and
    covers the Slackware Linux installation, basic GNU/Linux commands
    and the configuration of Slackware Linux. After reading this book,
    you should be prepared to use Slackware Linux for your daily work,
    and more than that. Hopefully this book is useful as a reference
    to more experienced Slackware Linux users as well.
  </p>

  <p>
    Thanks to the rapid development of open source software, there are
    now comprehensive desktop environments and applications for
    GNU/Linux. Most current distributions and books focus on using
    GNU/Linux with such environments. I chose to ignore most of the
    graphical applications for this book, and tried to focus this book
    on helping you, as a reader, to learn using GNU/Linux in a more
    traditional UNIX-like way. I am convinced that this approach is
    often more powerful, and helps you to learn GNU/Linux well, and
    not just one distribution or desktop environment. The UNIX
    philosophy is described in <a class="ulink" href="#chap-intro-unix" target="_top">the
    overview of UNIX philosophy</a>
  </p>

  <p>
    I wish everybody a good time with Slackware Linux, and I hope that
    you will find this book is useful for you.
  </p>

  <p>
    Daniël de Kok
  </p>

</div>

  <div class="part">
<div class="titlepage"><div><div><h1 class="title">
<a name="getstarted"></a>Part I. Per començar ??Getting started??</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="chapter"><a href="#chap-book">1. Quan a este llibre</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-book-availability">1.1. Disponibilitat</a></span></dt>
<dt><span class="sect1"><a href="#chap-book-conventions">1.2. Convencions</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-intro">2. Introducció a Slackware Linux</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-intro-linux">2.1. Què és Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-gnulinux">2.2. Qu és GNU/Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-slackware">2.3. Què és Slackware Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-unix">2.4. La filosofia UNIX</a></span></dt>
<dt><span class="sect1"><a href="#free-software">2.5. Programar lliure i de font oberta</a></span></dt>
<dt><span class="sect1"><a href="#slackware-features">2.6. Característiques de Slackware Linux 12.0</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-getting">2.7. Com aconseguir Slackware Linux (Getting Slackware Linux)</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-help">3. Fonts d'ajuda </a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-help-system">3.1. Al teu sistema</a></span></dt>
<dt><span class="sect1"><a href="#chap-help-internet">3.2. A la Internet</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#concepts">4. Conceptes generals</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#concepts-multitasca">4.1. Multitasca</a></span></dt>
<dt><span class="sect1"><a href="#concepts-fshierarchy">4.2. Jerarquia del sistema de fitxers </a></span></dt>
<dt><span class="sect1"><a href="#concepts-devices">4.3. Dispositius</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-install">5. La instal·lació de Slackware Linux </a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-install-bootcd">5.1. Llançar el CD d'instal·lació </a></span></dt>
<dt><span class="sect1"><a href="#chap-install-partitioning">5.2. Particionar un disc dur </a></span></dt>
<dt><span class="sect1"><a href="#chap-install-installing">5.3. Instal·lant Slackware Linux</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#getstarted-custominstall">6. Custom installation</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#getstarted-custominstall-partition">6.1. Partitioning a hard disk</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-initfs">6.2. Initializing and mounting filesystems</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-packages">6.3. Installing packages</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-config">6.4. Post-install configuration</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-script">6.5. Automated installation script</a></span></dt>
</dl></dd>
</dl>
</div>
    

    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-book"></a>Chapter 1. Quan a este llibre</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-book-availability">1.1. Disponibilitat</a></span></dt>
<dt><span class="sect1"><a href="#chap-book-conventions">1.2. Convencions</a></span></dt>
</dl>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-book-availability"></a>1.1. Disponibilitat</h2></div></div></div>
<p>
      Este llibre està escrit en DocBook/XML, i transformat en HTML i 
      XSL:FO mitjançant <span class="command"><strong>xsltproc</strong></span>. La darrera versió
      del llibre està sempre disponible a: <a class="ulink" href="http://www.slackbasics.org/" target="_top">http://www.slackbasics.org/</a>.
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-book-conventions"></a>1.2. Convencions</h2></div></div></div>
<p>
      Esta secció ofereix un breu resum de les convencions emprades al llibre.
    </p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-book-conventions-filenames"></a>1.2.1. Noms de fitxer</h3></div></div></div>
<p>
	Els noms de fitxers i de directoris estàn impresos així:
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/camí/a/fitxer</code></html:span>.  Per exemple:
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/fstab</code></html:span>
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-book-conventions-commands"></a>1.2.2. Comandaments ?Comandes?</h3></div></div></div>
<p>
	Els comandaments estàn impresos en negreta. Per exemple: <span class="command"><strong>ls
	-l</strong></span>
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-book-conventions-screenoutput"></a>1.2.3. Eixida per pantalla</h3></div></div></div>
<p>
	Les eixides per pantalla es veuen així:
      </p>
<pre class="screen">
Hola Món!
      </pre>
<p>
	Si els comandaments s'estàn introduïnt en la pantalla d'eixida,
	s'imprimiràn en negreta:
      </p>
<pre class="screen">
$ <span class="command"><strong>comandament</strong></span>
Eixida
      </pre>
<p>
	Si s'executa un comandament com a root, l'interpret es mostrarà 
	com <span class="quote">“<span class="quote">#</span>”</span>. Si un comandament s'executa amb un usuari normal
	sense privilegis, l'interpret es mostarà com
	<span class="quote">“<span class="quote">$</span>”</span>.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-book-conventions-notes"></a>1.2.4. Notes</h3></div></div></div>
<p>
	Algunes seccions contenen notes addicionals. No es necessari conéixer
	la informació de les notes, però proporcionen informació que pot ser valuosa
	 o enllaços a informació. Les notes s'imprimeixen així:
      </p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
	  Açò és una nota.
	</p></td></tr>
</table></div>
</div>
</div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-intro"></a>Chapter 2. Introducció a Slackware Linux</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-intro-linux">2.1. Què és Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-gnulinux">2.2. Qu és GNU/Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-slackware">2.3. Què és Slackware Linux?</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-unix">2.4. La filosofia UNIX</a></span></dt>
<dt><span class="sect1"><a href="#free-software">2.5. Programar lliure i de font oberta</a></span></dt>
<dt><span class="sect1"><a href="#slackware-features">2.6. Característiques de Slackware Linux 12.0</a></span></dt>
<dt><span class="sect1"><a href="#chap-intro-getting">2.7. Com aconseguir Slackware Linux (Getting Slackware Linux)</a></span></dt>
</dl>
</div>
  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-intro-linux"></a>2.1. Què és Linux?</h2></div></div></div>
    

    <p>
	Linux és un núcli tipus UNIX escrit per Linus Torvalds
	i altres desenvolupadors que corre en moltes arquitectures 
	diferents, per exemple a màquines IA32, IA64, Alpha, 
	m68k,SPARC i PowerPC. L'últim nucli així com 
	informació sobre el nucli Linux es pot trobar al lloc 
	web del núcli Linux: 
	<a class="ulink" href="http://www.kernel.org" target="_top">http://www.kernel.org</a>
      
    </p>

    <p>
      S'acostuma a confondre el nucli de Linux amb el sistema operatiu
      GNU/Linux. Linux é;gs només el nucli, no un sistema operatiu complet,
      mentres que GNU/Linux consiteix en el sistema operatiu de GNU amb el nucli Linux.
      La següent secció dóna un descripció més completa
      de GNU/Linux.
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-intro-gnulinux"></a>2.2. Qu és GNU/Linux?</h2></div></div></div>
    

    <p>
      En 1984 Richard Stallman encetà un ambiciós projecte 
      amb l'objectiu
      d'escriure un sistema operatiu lliure de tipus UNIX. El nom d'aquest 
      sistema és <acronym class="acronym">GNU</acronym>, què és
      l'acrònim de <span class="quote">“<span class="quote">GNU's Not UNIX</span>”</span> (GNU no és UNIX). Pel 
      volts de 1990, la
      majoria dels components del sistema operatiu GNU estàven escrits,
      a excepció del núcli. Això es deu a que dos anys abans, en 1988,
      es va decidir que el projecte GNU basaria el seu núcli en el 
      micro-núcli Mach 3.0, però no va ser fins el 1991 que el Mach 
      3.0 va ser alliberat sota una llicència lliure, just el mateix any 
      que Linus Torvalds va començar a omplir el buit deixat pel núcli
      al sistema GNU, escrivint el núcli Linux.
      
    </p>

    <p>
      El núcli de GNU, anomenat <span class="quote">“<span class="quote">HURD</span>”</span> es trobava en 
      desenvolupament quan es va escriure aquest llibre, i està 
      disponible com el sistema operatiu GNU/HURD. També hi ha alguns 
      altres núclis portats al sistema operatiu GNU, per exemple, el 
      projecte Debian ha desenvoupat una versió del sistema operatiu 
      GNU que treballa amb el núcli NetBSD.
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-intro-slackware"></a>2.3. Què és Slackware Linux?</h2></div></div></div>
    

    <p>
      Slackware Linux és una distribució de GNU/Linux mantinguda i
      desenvolupada per Patrick Volkerding. Una distribució és un 
      col·lecció coherent de programari que proporciona un sistema
      GNU/Linux funcional. Volkerding va començar a utilitzar GNU/Linux
      perquè necessitava un intèrpret de LISP per a un projecte i, en 
      aquell moment, la distribució GNU/Linux dominant era Softlanding 
      System Linux (SLS Linux). Així Slackware inicialment era una col·lecció
      privada de pegats de Volkerding per al SLS Linux, i el primer
      alliberament disponible públicament fou la versió 1.0, alliberada
      el 16 de Juliol de 1993.
      
    </p>

    <p>
      A diferència de moltes altres distribucions de GNU/Linux, Slackware
      Linux és fidel al anomenat principi KISS (Keep It Simple Stupid,
      mantin-ho simple, estúpid),
      el que significa que no té complexes eines gràfiques per a 
      configurar el sistema. Per aquesta raó malgrat que la corba d'aprenentatge
      de Slackware Linux pot ser alta per a l'usuari novell de GNU/Linux,
      açò proporciona una major transparència i flexibilitat, a més,
      s'aconsegueix un comprensió més profunda del GNU/Linux amb distribucions
      sense tantes facilitats, com Slackware Linux.
      
      
    </p>

    <p>
      Un altre aspecte diferencial de Slackware Linux, que a més
      <span class="quote">“<span class="quote">compleix</span>”</span> amb el principi KISS és el gestor de paquets. Slackware
      Linux no té un gestor de paquets com RPM o dpkg, els paquets són
      fitxers tgz (tar/gzip) corrents, sovint amb un guió d'instal·lació 
      addicional i un fitxer de descripció del paquet. Per als usuaris
      novells tgz és molt més potent que RPM, i evita problemes de 
      dependències. Un altra característica coneguda arreu són els seus
      scripts d'inicialització. A diferència d'altres distribucions,
      Slackware Linux no té un directori per a cada nivell d'execució
      amb enllaços simbòlics als servicis que s'han d'iniciar o matar
      en cadascún, utilitza una aproximació molt més senzilla en la que 
      es pot habilitat o deshabilitar servicis canviat el permís d'execució
      d'un script d'inicialització.
 
      
    </p>

    <p>
      Els paquets de Slackware Linux estàn compilats amb tan poques 
      modificacions com ha sigut possible. Açò vol dir que la major 
      part de documentació genèrica relativa a GNU/Linux aprofita per 
      a Slacwkare Linux.
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-intro-unix"></a>2.4. La filosofia UNIX</h2></div></div></div>
    

    <p>
      Com GNU/Linux és una reimplantació lliure del sistema operatiu UNIX,
      és una bona idea fer un colp dull a la filosofia que va fer al UNIX
      estimat arreu. Doug McIlroy va resumir la filosofia UNIX en tres 
      regles senzilles:
      
    </p>

    <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
        <p>
          Escriu programes que facen una cosa i que la facen ben feta.
        </p>
      </li>
<li class="listitem">
        <p>
          Escriu programes per a treballar junts. 
        </p>
      </li>
<li class="listitem">
        <p>
	  Escriu programes per a manipular fluxes, perquè això és una
	  interfície universal.
          
        </p>
      </li>
</ul></div>

    <p>
      L'habitual és que no tingues intenció d'escriure programes 
      per al GNU/Linux. Tanmateix, inclús com a usuari bàsic, les regles
      bàsiques de UNIX poden significar molt per a tú. Una vegada 
      aconseguisques conéixer les ordres essencials que han format part
      d'un sistema UNIX al llarg de molt anys, seràs capaç de combinar
      programes senzills per a resoldre problemes complexos. Tin açò 
      en ment mentres aprens Slackware Linux i intenta fer-te una idea
      de com pots dividir tasques complexes en combinacions d'operacions
      senzilles.

      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="free-software"></a>2.5. Programar lliure i de font oberta</h2></div></div></div>
    

    <p>
      La majoria dels paquets de Slackware Linux estàn publicats sota
      llicència de programari lliure o de font oberta. Baix aquestes 
      llicències el programari es pot utilitzar, estudiar, canviar i 
      distribuïr lliurement. En la pràctica, açò significa que el 
      programari es troba disponible i redistribuible tant en forma de 
      codi font com de binari. Malgrat que els moviments del programari 
      lliure i el de codi obert comparteixen moltes llicències i 
      principis, hi ha diferències subtils entre ells. El moviment
      del programari de codi obert tendeix a posar l'accent en els
      avantatges tècnics i econòmics de compartir el codi font, mentres
      que el moviment del programari lliure posa l'accent en els aspectes
      ètics de proporcionar codi font i binaris lliurement. 
      
      Com posa al lloc web de GNU:<span class="quote">“<span class="quote">El software lliure és una
      qüestió de llibretat, no de preu. Per a comprendre el concepte,
      hauries de pensar en lliure com en llibertat d'expresió i no com 
      en barra lliure.<a href="#ftn.idm951924596" class="footnote" name="idm951924596"><sup class="footnote">[1]</sup></a></span>”</span>
    Fidel a l'esperit del programari lliure i al de font oberta, el codi font
    de quasi tots els paquets està inclòs al conjunt de CDs oficials i al DVD
    de Slackware Linux.
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="slackware-features"></a>2.6. Característiques de Slackware Linux 12.0</h2></div></div></div>
    

    <p>
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	  <p>
	    <span class="bold"><strong>Linux 2.6.21.5</strong></span> -
	    Sí, Slackware Linux utilitza un núcli Linux així de modern i de
	    tan alt rendiment. El núcli inclou suport per a totes les 
	    controladores de disk modernes, LVM, RAID per programari,
	    discos xifrats, i múltiples processadors/nuclis. Per defecte,
	    l'<span class="emphasis"><em>udev</em></span> està habilitat per a la gestió 
	    automàtica de nodes de dispositiu.
	    
          </p>
	</li>
<li class="listitem">
	  <p>
	    <span class="bold"><strong>HAL</strong></span> - Ara, la  HAL (Hardware 
	    Abstaction Layer, capa d'abstracció de maquinari) està inclosa
	    també. Açò proporciona una API uniforme per a l'ús del maquinari
	    per aplicacions d'escriptori, el que fa considerablement més 
	    senzill el muntatge de discos i CD's sota Xfce i KDE.

	    
	  </p>
	</li>
<li class="listitem">
	  <p>
	    <span class="bold"><strong>X11 7.2.0</strong></span> - Aquesta és la
	    primera versió de Slackware Linux en utilitzar X modular. Açò 
	    significa que els components que formen X11 estàn separats en
	    molt paquets menuts per a facilitar el manteniment i alleugerir
	    les actualitzacions.
            
          </p>
        </li>
<li class="listitem">
          <p>
            <span class="bold"><strong>GCC 4.1.2</strong></span> - Slackware
            Linux 12.0 inclou un kit d'eines totalment revisat
	    basat en la GNU Compiler Collection 4.1.2. GCC proporciona 
	    compiladors de C, C++, Objective-C, Fortran-77/95 i Ada 95.
	    A més, s'utilitza la versió 2.5 de la llibreria GNU de C.
	    
	    
          </p>
        </li>
<li class="listitem">
	  <p>
	    <span class="bold"><strong>Apache 2.2.4</strong></span> - Apache
	    va ser ascendit a una nova versió major. Apache 2.x és
	    una reescriptura substancial de la antiga serie 1.3.x
	    
	  </p>
	</li>
<li class="listitem">
          <p>
	    <span class="bold"><strong>El K Desktop Environment (KDE)
            3.5.7</strong></span> - Es proporciona l'entorn KDE al complet, el
	    que inclou KOffice, el navegador web Konqueror, programes
	    multimèdia, eines de desenvolupament, i moltes altres
	    aplicacions útils.
            
          </p>
        </li>
<li class="listitem">
          <p>
	    <span class="bold"><strong>Xfce 4.4.1</strong></span> - Xfce és entorn
	    d'escriptori lleuger basat en GTK2. Abraça l'esperit UNIX de
	    modularitat i reusabilitat.
            
          </p>
        </li>
</ul></div>
<p>
    </p> 
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-intro-getting"></a>2.7. Com aconseguir Slackware Linux (Getting Slackware Linux)</h2></div></div></div>
    

    <p>
      Slackware Linux es pot descarregar lliurement des dels espills
      oficials de Slackware. La llista d'espills està disponible a
       <a class="ulink" href="http://www.slackware.com/getslack/" target="_top">http://www.slackware.com/getslack/</a>.
    </p>

    <p>
      També es pot encarregar Slackware Linux com a un conjunt de CD 
      o un DVD a la botiga de Slackware. Moltes botigues d'Internet 
      ofereixen Slackware Linux en CD-ROM o DVD més barat que a la botiga oficial,
      però només estaràs ajudant econòmicament Slackware Linux si compres 
      un conjunt de CDs oficial, o un DVD. La Slackware Store també ofereix 
      suscripcions a Slackware Linux. Un suscriptor rep automàticament 
      els nous alliberaments a un preu reduït.
      
    </p>

    <p>
      Si t'agradaria tindre més informació respecte a la compra de
      Slackware Linux, visita el lloc web de la Slackware Store a
      <a class="ulink" href="http://store.slackware.com/" target="_top">http://store.slackware.com/</a>.
    </p>
  </div>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.idm951924596" class="footnote">
      
      <p><a href="#idm951924596" class="para"><sup class="para">[1] </sup></a>
	<a class="ulink" href="http://www.gnu.org/philosophy/free-sw.html" target="_top">http://www.gnu.org/philosophy/free-sw.html</a>
      </p>
    </div>
</div>
</div>
    <div lang="en" class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-help"></a>Chapter 3. Fonts d'ajuda </h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-help-system">3.1. Al teu sistema</a></span></dt>
<dt><span class="sect1"><a href="#chap-help-internet">3.2. A la Internet</a></span></dt>
</dl>
</div>
  

  <p>
	Hi ha un conjunt molt ric d'informació disponible sobre molts temes relacionats
	amb el GNU/Linux. La més general és aplicable a Slackware Linux, perque
	el programari incorporat a la distribució s'ha compilat des de codis font
	que han patit les mínimes alteracions possibles. Aquest capítol
	proporciona alguns enllaços a informació i documentació que es pot 
	trobar tant a un sistema amb Slackware Linux instal·lat, com a Internet.
  </p>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-help-system"></a>3.1. Al teu sistema</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-help-system-howtos"></a>3.1.1. HOWTO's de Linux</h3></div></div></div>
      

      <p>
	Els HOWTOs (COM FER) de Linux són una colecció de de documents que cobreixen
	temes específics relacionats amb GNU/Linux. Molts HOWTOs de Linux no 
	van lligats a una distribució específica, pel que són molt útils 
	per als usuaris de Slackware Linux. 
	El paquet <span class="emphasis"><em>linux-howtos</em></span> en el grup de programari
	<span class="quote">“<span class="quote">f</span>”</span> conté la col·lecció de HOWTOs. Després d'instal·lar-lo, estaràn
	disponibles al directori <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/doc/Linux-HOWTOs/</code></html:span>.
	Slackware Linux conté, a més, una xicoteta col·lecció de <acronym class="acronym">FAQs</acronym>
	relacionades amb Linux (Les FAQ són documents que respones preguntes frequents). 
	Les FAQs de Linux es troben instal·lades al directori 
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/doc/Linux-FAQs/</code></html:span> i estàn disponibles al paquet
	<span class="emphasis"><em>linux-faqs</em></span>, que forma part del grup <span class="quote">“<span class="quote">f</span>”</span> 
	de programari.        
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-help-system-manpages"></a>3.1.2. Pàgines de manual</h3></div></div></div>
      

      <p>
	La majoria de comandaments tipus UNIX estàn coberts pel sistema
	tradicional d'ajuda de UNIX, les anomenades <span class="emphasis"><em>pàgines de manual</em></span>.
	Es pot llegir la pàgina de manual d'un programa amb la ordre 
	<span class="command"><strong>man</strong></span>. Al executar <span class="command"><strong>man</strong></span> amb el nom d'un
	comandament com a argument, es mostrarà la pàgina de manual corresponent.
	Per exemple,
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>man ls</code></strong>
      </pre>

      <p>
	mostra la pàgina de manual del comandament <span class="command"><strong>ls</strong></span>.
      </p>

      <p>
	Si no saps el nom exacte d'una pàgina de manual o d'un comandament,
	pots buscar una paraula clau a les pàgines de manual. La opció 
	<em class="parameter"><code>-k</code></em> proporciona aquesta funcionalitat:
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>man -k rmdir</code></strong>
hrmdir               (1)  - remove an empty HFS directory
rmdir                (1)  - remove empty directories
rmdir                (2)  - delete a directory
      </pre>

      <p>
	La col·lecció de pàgines de manual és molt extensa, i abarca 
	més temes a banda dels comandaments. Les següents seccions estàn 
	disponibles.
        
      </p>

      <div class="literallayout"><p><br>
1   Programes executables o ordres de l'interpret <br>
2   Crides al sistema (funcions proporcionades pel núcli) <br>
3   Crides de funció (funcions dins de llibreries de programa) <br>
4   Fitxers especials (trobats habitualment a /dev) <br>
5   Formats de fitxer i convencions p.ex. /etc/passwd <br>
6   Jocs <br>
7   Miscel·lània (incloent paquets de macros i convencions, p.ex. man(7), groff(7)<br>
8   Comandaments d'administració del sistema (normalment només per al root) <br>
9   Rutines de Linux [No estàndard] <br>
      </p></div>

      <p>
	Si més d'una secció conté una pàgina de manual amb un nom específic,
	com per exemple <span class="command"><strong>rmdir</strong></span>, pots triar quina pàgina vols veurer
	afegint el nombre de secció abans del nom de la pàgina de manual. Per exemple:
        
      </p>

      <pre class="screen">
<strong class="userinput"><code>man 2 rmdir</code></strong>
      </pre>

      <p>
	Si volgueres imprimir una pàgina de manual en una impressora que tingueres
	instal·lada, podries connectar la eixida de <span class="command"><strong>man</strong></span> al comandament
	<span class="command"><strong>lpr</strong></span>. Quan s'empra la opció <em class="parameter"><code>-t
        </code></em> del comandament <span class="command"><strong>man</strong></span>, este manará la pàgina
	de manual en format Postscript enlloc d'ASCII a la seua eixida. Per exemple,
	es pot emprar el següent comandament per a imprimir la pàgina de manual de
	<span class="command"><strong>cat</strong></span>:
        
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>man -t cat | lpr</code></strong>
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-help-internet"></a>3.2. A la Internet</h2></div></div></div>
    

    <p>
      Hi ha molts llocs web i forums relacionats amb GNU/Linux i 
      Slackware Linux a la Internet, però molts d'aquests sovint 
      desapareixen tan ràpid com apareixen, a més la informació en molts
      llocs web està fragmentada. Els següents recursos han estat 
      actius durant molt de temps, i proporcionen bons contingunts.
      
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-help-internet-slacksite"></a>3.2.1. El lloc web de Slackware Linux</h3></div></div></div>
      

      <p>
	El lloc web de Slackware Linux pot estar una miqueta desfasat de vegades,
	però proporciona mols recursos útils.
	    
        
      </p>

      <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	  <p>
	    Una pàgina de notícies que anuncia nous alliberaments i llista
	    altres notícies importants que són rellevants per a Slackware Linux.
            
	  </p>
	</li>
<li class="listitem">
	  <p>
	    Un resum dels canvis patits per la distribució es proporciona 
	    mitjançant un format estructurat anomenat <span class="emphasis"><em>ChangeLog</em></span>.
	    Es proporcionen ChangeLog's tant de la versió actual de desenvolupament, 
	    com de l'últim alliberament estable.
            
          </p>
        </li>
<li class="listitem">
          <p>
	    Hi ha dues llistes de distribució a les que et pots subscriure.
	    La llista <span class="emphasis"><em>slackware-announce</em></span> acostuma a 
	    anunciar nous alliberaments de Slackware Linux, mentres que 
	    les actualitzacions de seguretat s'anuncien a la llista
	    <span class="emphasis"><em>slackware-security</em></span>.
            
          </p>
        </li>
<li class="listitem">
          <p>
	    Un llista dels espills on es pot descarregar Slackware Linux.
	    
            
          </p>
        </li>
<li class="listitem">
          <p>
	    Documentació diversa, incloent una llista de 
	    preguntes freqüents i el llibre <span class="emphasis"><em>Slackware 
	    Linux Essentials</em></span>.
            
          </p>
        </li>
</ul></div>

      <p>
	El lloc web de Slackware Linux està disponible a:
	
	<a class="ulink" href="http://www.slackware.com/" target="_top">http://www.slackware.com/</a>
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-help-internet-linuxquestions"></a>3.2.2. LinuxQuestions</h3></div></div></div>
      

      <p>
	LinuxQuestions és un enorme forum amb prous membres
	dispostos a ajudar. És de particular interés
	el subforum de Slackware Linux, on pots buscar assistència
	per a resoldre els problemes que pogueres tindre amb Slackware Linux.
	El forum LinuxQuestions està disponible a:
        
	<a class="ulink" href="http://www.linuxquestions.org/" target="_top">http://www.linuxquestions.org/</a>
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-help-internet-aols"></a>3.2.3. alt.os.linux.slackware</h3></div></div></div>
      

      <p>
	<span class="emphasis"><em>alt.os.linux.slackware</em></span> és un 
	grup de notícies de Slackware Linux. Pots llegir aquests grups  
	amb un lector de notícies com ara tin o slrn, a través
	del servidor de grups de notícies del teu proveïdor
	d'accés a Internet. En aquest grup de notícies
	s'espera que hages llegit llegit tota la documentació
	necessària abans de publicar preguntes. Si no ho has fet
	i ha moltes possibilitats de que sigues <span class="quote">“<span class="quote">fulminat</span>”</span>.
        
      </p>
    </div>
  </div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="concepts"></a>Chapter 4. Conceptes generals</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#concepts-multitasca">4.1. Multitasca</a></span></dt>
<dt><span class="sect1"><a href="#concepts-fshierarchy">4.2. Jerarquia del sistema de fitxers </a></span></dt>
<dt><span class="sect1"><a href="#concepts-devices">4.3. Dispositius</a></span></dt>
</dl>
</div>
<p>
    Aquest capítol ofereix una introducció a alguns conceptes generals de UNIX 
    i de GNU/Linux. És important llegir este capítol completament si no 
    tens gens d'experiència en UNIX o GNU/Linux ja que molts dels conceptes 
    coberts ací s'utilitzen en este llibre i a GNU/Linux.
    
  </p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts-multitasca"></a>4.1. Multitasca</h2></div></div></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts-multitasking-intro"></a>4.1.1. Introducció</h3></div></div></div>
<p>
	Tradicionalment, un dels punts forts del UNIX és la multitasca 
	(mulititasquing). El concepte multitasca significa que múltiples 
	programes poden	estar executant-se alhora. Potser t'estàs preguntant 
	per què açò és important, ja que molta gent utilitza només una aplicació 
	alhora. La multitasca és una necessitat fonamental per als sistems tipus 
	UNIX, encara que no hages arrancat cap aplicació hi ha programes 
	executant-se al fons. Per exemple, alguns programes proporcionen servicis 
	de xarxa, mentre que d'altres mostren una sol·licitud de inici de sessió 
	i esperen a que un usuari inicie sessió en un terminal (virtual). Els
	programes que s'executen al fons solen anomenar-se processos <span class="emphasis"><em>
	dimoni (daemon)</em></span>--&gt;
        <a href="#ftn.idm951838204" class="footnote" name="idm951838204"><sup class="footnote">[2]</sup></a>.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts-multitasking-procsthreads"></a>4.1.2. Processos i fils </h3></div></div></div>
<p>
	Després de que un programa es carregue des d'un mitjà 
	d'emmagatzematge, s'inicia una instància del programa,
	aquesta instància s'anomena <span class="emphasis"><em>procés (process)</em></span>.
	Un procés té la seua pròpia memòria protegida, anomenada
	<span class="emphasis"><em>espai d'adreçament de procés</em></span>. L'espai
	d'adreçament de procés té dos àrees importants: l'àrea de
	<span class="emphasis"><em>text</em></span> i l'àrea de <span class="emphasis"><em>dades</em></span>.
	La primera és el codi del programa en si; s'utilitza per a
	dir-li al sistema el que ha de fer, mentres que la segona
	és utilitzada per a emmagatzemar dades constants i de temps
	d'execució. El sistema operatiu li assigna a cada procés temps
	per a executar-se. En sistemes d'un sol processador, els
	processos no estàn corrent simultàniament, en realitat 
	un planificador intel·ligent al núcli divideix temps de CPU
	entre els processos, proporcionant la il·lusió de que els
	processos corren alhora. Este procés s'anomena 
	<span class="emphasis"><em>time-sharing</em></span> (compartició de temps).
	A sistemes amb més d'una CPU o varis núclis de CPU, més d'un procés
	pot executar-se simultàniament, però la compartició de temps
	segueix utilitzant-se per a dividir el temps de CPU disponible
	entre processos.
	

        
      </p>
<p>
	Es creen nous processos duplicant un procés en marxa amb la 
	crida al sistema <span class="command"><strong>fork</strong></span> (bifurcar). 
	<a class="xref" href="#fork" title="Figure 4.1. Bifurcant un procés (forking)">Figure 4.1, “Bifurcant un procés (forking)”</a> mostra una crida a fork() en acció de
	manera esquemàtica. El procés pare emet una crida a fork(),
	el núcli respon a esta crida duplicant el procés, i 
	anomenant a un procés el <span class="emphasis"><em>pare</em></span> i a l'altre 
	el <span class="emphasis"><em>fill</em></span>.
        
      </p>
<div class="figure">
<a name="fork"></a><p class="title"><b>Figure 4.1. Bifurcant un procés (forking)</b></p>
<div class="figure-contents"><div class="mediaobject"><img src="../../images/fork.png" alt="Bifurcant un procés (forking)"></div></div>
</div>
<br class="figure-break"><p>
	Les bifurcacions poden utilitzar-se per un programa per a crear dos
	procesos que poden córrer simultàniament en màquines 
	multiprocessador. Tanmateix, sovint no és ideal, perque tots
	dos processos tindran el seu propi espai d'adreçament, a més, la
	duplicació inicial de la memòria del procés pren relativament
	molt de temps, i és difícil compartir informació entre els dos
	processos. Aquest problema es resol amb un concepte anomenat
	<span class="emphasis"><em>multithreading</em></span> (multi-filat). Multithreading
	significa que vàries instàncies de la mateixa àrea de text es poden
	córrer alhora, compartint l'àrea de dades. Aquestes instàncies,
	anomeneades fils (threads), poden executar-se en paral·lel en 
	múltiples CPUs.
	
        
      </p>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts-fshierarchy"></a>4.2. Jerarquia del sistema de fitxers </h2></div></div></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts-fshierarchy-structure"></a>4.2.1. Estructura</h3></div></div></div>
<p>
	El sistemes operatius emmagatzemen informació en sistemes de 
	fitxers. Un sistema de fitxers és bàsicament una estructura
	en forma d'arbre que sosté directoris i fitxers, com el sistema
	operatiu, programes d'usuari i dades d'usuari. La majoria de
	sistemes de fitxers poden, a més emmagatzemar diverses meta-dades
	relatives a fitxers i directoris, per exemple els temps d'accés i 
	de modificació. A GNU/Linux només hi ha una jerarquia de sistemes
	de fitxers, açò significa que GNU/Linux no té lletres d'unitat
	(com A:, C:, D:) per als distints sistemes de fitxers, com DOS
	o Windows. El sistema de fitxers és vist com un arbre, amb un
	directori arrel (que no té directori pare), branques, i fulles
	(directoris sense subdirectoris). El directori arrel sempre
	es denota amb una barra (<span class="quote">“<span class="quote">/</span>”</span>) i els directoris es
	separen amb el mateix caràcter.

        
      </p>
<div class="figure">
<a name="filesystem-structure"></a><p class="title"><b>Figure 4.2. La estructura del sistema de fitxers </b></p>
<div class="figure-contents"><div class="mediaobject"><img src="../../images/fs-structure.png" alt="La estructura del sistema de fitxers"></div></div>
</div>
<br class="figure-break"><p>
	<a class="xref" href="#filesystem-structure" title="Figure 4.2. La estructura del sistema de fitxers">Figure 4.2, “La estructura del sistema de fitxers ”</a> mostra la estructura d'un
	sistema de fitxers. Pots veurer que el directori arrel 
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span> té dos directoris fill:
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">bin</code></html:span> i <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">home</code></html:span>. El directori
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">home</code></html:span> té dos directoris fill,
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">joe</code></html:span> i <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">jack</code></html:span>. El 
	diagrama mostra el camí complet a cada directori. La mateixa
	notació s'utilitza amb els fitxers. Suposem que hi ha un fitxer
	anomenat <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">memo.txt</code></html:span> al directori
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home/jack</code></html:span>, el camí complet al fitxer és 
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home/jack/memo.txt</code></html:span>.

        
      </p>
<p>
	Cada directori té dos entrades especials, 
	<span class="quote">“<span class="quote"><html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.</code></html:span></span>”</span>, i
        <span class="quote">“<span class="quote"><html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">..</code></html:span></span>”</span>. La primera fa
	referència al propi directori i la segona al directori
	pare. Aquestes entrades es poden utilitzar per a contruir
	camins relatius. Si estàs treballant al directori
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">jack</code></html:span>, pots referenciar el directori
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home/joe</code></html:span> amb 
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">../joe</code></html:span>.

        
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts-fshierarchy-mounting"></a>4.2.2. Muntant </h3></div></div></div>
<p>
	Potser et preguntes com és possible accedir a altres
	dispositius o particion més enllà de la partició de disc que
	sosté el sistema de fitxers. Linux utilitza la mateixa 
	aproximació que UNIX per a accedir a altres sistemes de
	fitxers. Linux permet a l'administrador del sistema connectar
	un dispositiu a qualsevol directori en la estructura de 
	fitxers. Aquest procés s'anomena <span class="emphasis"><em>muntatge 
	(mounting)</em></span>. Per exemple, es pot muntar la 
	unitat de CD-ROM al directori <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/cdrom</code></html:span>.
	Si el muntatge és correcte, els fitxers que hi ha al 
	CD-ROM es poden accedir a través d'aquest directori. El
	procés de muntatge es descriu en detall a <a class="xref" href="#basics-filesystem-mounting" title="8.8. Mounting filesystems">Section 8.8, “Mounting filesystems”</a>.

        
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts-fshierarchy-commondirs"></a>4.2.3. Directoris comuns </h3></div></div></div>
<p>
	El Filesystem Hierarchy Standard Group ha intentat crear
	un estàndard que descriu quins directoris haurien d'estar
	disponibles a un sistema GNU/Linux. Actualment, les
	distribucions més importants utilitzen la Jerarquia 
	Estàndard de Sistema de Fitxers (FHS, de l'anglés 
	Filesystem Hierarchy Standard) com a directriu. Aquesta
	secció descriu alguns directoris obligatoris als sistemes
	GNU/Linux.

        
      </p>
<p>
	Per favor, tin en compte que GNU/Linux no té un directori
	separat per a cada aplicació (com Windows). Per contra, els
	fitxers s'organitzen per funció i tipus. Per exemple, els
	binaris per a la majoria d'aplicacions d'ús comú, estàn
	emmagatzemats a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/bin</code></html:span>, i les seues
	llibreries a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/lib</code></html:span>. Aquest és un 
	curt resum dels directoris més importants en un sistema 
	Slackware Linux:

        
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
            <span class="bold"><strong>/bin</strong></span>: 
	    binaris essencials de l'usuari que haurien d'estar disponibles
	    fins i tot quan <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr</code></html:span> no estiga muntat.
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/dev</strong></span>: fitxers de dispositiu.
	    Hi ha fitxers especials utilitzats per a accedir a determinats
	    dispositius.
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/etc</strong></span>: El direcotori
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc</code></html:span> conté tots els fitxers de
	    configuració importants.
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/home</strong></span>: conté els directoris
	    llar per a usuaris individuals
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/lib</strong></span>: llibreries essecials
	    del sistema (com glibc) i els mòduls del núcli.
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/root</strong></span>: el directori llar
	    del usuari <span class="emphasis"><em>root</em></span>.
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/sbin</strong></span>: binaris essencials
	    que s'utilitzen en l'administració del sistema.
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/tmp</strong></span>: un directori 
	    per a fitxers temporals on tothom pot escriure. 
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/usr/bin</strong></span>: Emmagatzema
	    la majoria dels binaris d'usuari.
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/usr/lib</strong></span>: llibreries que
	    no són essencials per a llançar el sistema
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/usr/sbin</strong></span>: binaris 
	    per a l'administració del sistema que no són essencials.
	    
          </p></li>
<li class="listitem"><p>
            <span class="bold"><strong>/var</strong></span>: fitxers de dades
	    variables, com bitàcores (logs).
	    
          </p></li>
</ul></div>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="concepts-devices"></a>4.3. Dispositius</h2></div></div></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts-devices-intro"></a>4.3.1. Introducció</h3></div></div></div>
<p>
	A GNU/Linux virtualment tot està representat per un fitxer, incloent els
	dispositius. Tot sistema GNU/Linux té un directori amb fitxers especials,
	anomenat <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev</code></html:span> i cada fitxer en aquest directori 
	representa un dispositiu o un pseudo-dispositiu. Un fitxer de dispositiu
	té dos números associats, el <span class="emphasis"><em>major</em></span> (principal) i
	el <span class="emphasis"><em>minor</em></span> (secundari). El ńucli sap quin dispositiu
	és representat per un fitxer de dispositiu mitjançants estos números de
	dispositiu. El següent exemple mostra el números de dispositiu per al
	fitxer de dispositiu <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/zero</code></html:span>:

        
      </p>
<pre class="screen">
$ <span class="command"><strong>file /dev/zero</strong></span>
/dev/zero: character special (1/5)
      </pre>
<p>
	La ordre <span class="command"><strong>file</strong></span> es pot utilitzar per a determinar
	el tipus d'un fitxer. Aquest fitxer en particular és reconegut com
	un fitxer de dispositiu que té l'<span class="emphasis"><em>1</em></span> com el 
	número principal de dispositiu i, el <span class="emphasis"><em>5</em></span> com el
	número secundari de dispositiu.
	
        
      </p>
<p>
	Si has instal·lat el paquet de les fonts del núcli, pots
	trobar un llista completa de tots els dispositius principals
	amb els	seus números principals i secundaris a  
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/src/linux/Documentation/devices.txt</code></html:span>.
	Una llista actualitzada està disponible on-line a través de
	Linux Kernel Archives
        <a href="#ftn.idm951797724" class="footnote" name="idm951797724"><sup class="footnote">[3]</sup></a>.
      </p>
<p>
	El núcli Linux maneja dos tipus de dispositius:
	de <span class="emphasis"><em>caràcter</em></span> i de <span class="emphasis"><em>bloc</em></span>.
	Els dispositius de caràcter es poden llegir byte a byte, els 
	dispositius de bloc no, aquest són llegits per blocs (per exemple
	4096 bytes cada vegada). Que un dispositiu siga de caràcter o de
	bloc depén de la naturalesa del dispositiu. Per exemple, la majoria
	de dispositius d'emmagatzematge són dispositius de bloc, i la majoria de
	dispositius d'entrada ho són de caràcter. El dispositius de bloc 
	tenen un avantatge distintiu, diguem que poden utilitzar el cau. 
	Açò significa que els blocs que es lligen o s'escriuen amb
	freqüència són emmagatzemats en una zona especial de la memòria del
	sistema anomenada memòria cau (cache). La memòria és molt més
	ràpida que la majoria del medis d'emmagatzematge, amb la qual cosa
	es pot guanyar molt de rendiment realitzant operacions comunes de
	lectura i escriptura a la memòria. Pressupost que, finalment, els canvis
	han de ser escrits al medi d'emmagatzematge per a reflectir els canvis
	fets a la memòria cau.
	
        
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="concepts-devices-atascsi"></a>4.3.2. Dispositius ATA i SCSI</h3></div></div></div>
<p>
	Hi ha dos classes de dispositius de bloc que anem a analitzar en detall,
	perque comprendre l'anomenament d'aquests dispositius és crucial per a 
	particionar un disc dur i muntar-lo. Quasi tots els ordinadors moderns 
	amb una	arquitectura x86 utilitzen discs i CD-ROMs ATA. Baix linux 
	aquests	dispositius s'anomenen de la següent manera:
        
      </p>
<pre class="screen">
/dev/hda - dispositiu mestre en el primer canal ATA
/dev/hdb - dispositiu esclau en el primer canal ATA
/dev/hdc - dispositiu mestre en el segon canal ATA
/dev/hdd - dispositiu esclau en el segon canal ATA
      </pre>
<p>
	En la majoria d'ordinadors amb un únic disc dur, aquest és el dispositiu 
	mestre al primer canal ATA (<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hda</code></html:span>), i el CD-ROM
	és el dispositiu mestre del segon canal ATA. Les particions del
	disc dur s'anomenen com el nom del disc que les sosté més un número.
	Per exemple, <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hda1</code></html:span> és la primera partició 
	del disc representat pel fitxer de dispositiu 
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hda</code></html:span>.
	
        
      </p>
<p>
	Els discs SCSI i els dispostius CD-ROM segueixen una altra convenció
	de noms. SCSI no és d'ús comú en la majoria de màquines de perfil baix,
	però les unitats USB i Serial ATA (SATA) són representades com discs
	SCSI. La següent notació s'utilitza per a les unitats SCSI:

        
      </p>
<pre class="screen">
/dev/sda - Primer disc SCSI
/dev/sdb - Segon disc SCSI
/dev/sdc - Tercer disc SCSI
/dev/scd0 - Primer CD-ROM
/dev/scd1 - Segon CD-ROM
/dev/scd2 - Tercer CD-ROM
      </pre>
<p>
	Els noms de les particions es construeixen de la mateixa manera que 
	als discs ATA, així <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/sda1</code></html:span> és la primera partició
	en el primer disc SCSI.
        
      </p>
<p>
	Si utilitzes la implementació RAID de programari del núcli Linux,
	els volums RAID estàn disponibles com <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/mdn</code></html:span>,
	on la <span class="emphasis"><em>n</em></span> és el número de volum començant per 0. 
        
      </p>
</div>
</div>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.idm951838204" class="footnote"><p><a href="#idm951838204" class="para"><sup class="para">[2] </sup></a>
	    Malgrat que <span class="emphasis"><em>daemon</em></span> es tradueix al valencià com 
	    a dimoni, en anglés no són la mateixa paraula i aquesta fa referència 
	    a uns éssers sobrenaturals de la mitologia grega, una mena d'esperits 
	    que tenien un cert poder sobre els homes, una mena de semi-Deus.
            
          </p></div>
<div id="ftn.idm951797724" class="footnote"><p><a href="#idm951797724" class="para"><sup class="para">[3] </sup></a>
            <a class="ulink" href="ftp://ftp.kernel.org/pub/linux/docs/device-list/" target="_top">ftp://ftp.kernel.org/pub/linux/docs/device-list/</a>
          </p></div>
</div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-install"></a>Chapter 5. La instal·lació de Slackware Linux </h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-install-bootcd">5.1. Llançar el CD d'instal·lació </a></span></dt>
<dt><span class="sect1"><a href="#chap-install-partitioning">5.2. Particionar un disc dur </a></span></dt>
<dt><span class="sect1"><a href="#chap-install-installing">5.3. Instal·lant Slackware Linux</a></span></dt>
</dl>
</div>
  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-install-bootcd"></a>5.1. Llançar el CD d'instal·lació </h2></div></div></div>
    

    <p>
		El mètode més senzill per a llançar el sistema d'instal·lació és
		mitjançant el CD-ROM d'instal·lació. Aquest és un CD arrencable,
		el que significa que la BIOS pot llançar el CD, de la mateixa 
		manera que pot llançar, per exemple, un disquet. La majoria dels
		sistemes moderns porten una BIOS que suporta la càrrega de CD-ROM.
		
      
    </p>

    <p>
		Si una vegada inserit el CD, no es carrega al engegar-se el sistema,
		normalment vol dir que la seqüència de llançament no està 
		configurada correctament a la BIOS. Accedeix a la configuració 
		de la BIOS (normalment açò es pot aconseguir pitjant la tecla
		&lt;Del&gt; o &lt;Esc&gt; quan apareix la pantalla de la BIOS).
		i assabentar-te que el CD-ROM està dalt de tot en la llista en 
		la seqüència de llançament. És possible que si estàs utilitzant 
		un CD-ROM SCSI tingues que configurar la seqüència a la BIOS de
		SCSI, enlloc de la BIOS del sistema. Per a més informació 
		consulta el manual de la targeta SCSI.
      
    </p> 

    <p>
		Quan el CD-ROM es carrega, apareix una pantalla de pre-llançament.
		Normalment, es pot pitjar senzillament &lt;ENTER&gt; per a procedir
		a la càrrega del núcli Linux per defecte ((<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hugesmp.s
		</code></html:span>). Este núcli requereix, almenys, una CPU Pentium PRO.
		Es pot llançar un núcli alternatiu introduïnt el nom del núcli
		al símbol del sistema i pitjant &lt;ENTER&gt;. La taula següent
		llista els diferents núclis disponibles al CD/DVD de Slackware 
		Linux.
      
    </p>

    <div class="table">
<a name="chap-install-bootcd-installkernels"></a><p class="title"><b>Table 5.1. Núclis d'instal·lació</b></p>
<div class="table-contents">
      

      <table summary="Núclis d'instal·lació" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Linux</th>
<th>Descripció</th>
</tr></thead>
<tbody>
<tr>
<td>huge.s</td>
<td>
			Abans, hi havia núclis específics per a les diferents 
			controladores de disc. Els nous núclis huge(enorme) inclouen
			suport per a totes les controlades ATA, SATA i SCSI comunes.
			Este núcli no incorpora suport per a SMP, i funciona en 
			processadors i486 i més moderns. Si tens una CPU Pentium Pro
			o més moderna, es recomana utilitzar el núcli <span class="emphasis"><em>
			hugesmp.s</em></span>, fins i tot en sisteme amb només un 
			processador.
		  
	    </td>
</tr>
<tr>
<td>hugesmp.s</td>
<td>
			El núcli <span class="emphasis"><em>hugesmp.s</em></span> té suport per a les
			controladores ATA, SATA i SCSI més comunes, a més, este núcli
			incorpora suport SMP. Aquest és el núcli recomanat amb CPUs
			Pentium PRO i més modernes.
	      
	    </td>
</tr>
<tr>
<td>speakup.s</td>
<td>
			Aquest núcli és comparabla al <span class="emphasis"><em>huge.s</em></span>,
			per afegeix suport per a  de maquinari de sistetitzadors de 
			veu.
	      
	    </td>
</tr>
</tbody>
</table>
    </div>
</div>
<br class="table-break">

    <p>
		Després de llançar el sistema d'instal·lació, se't preguntarà si
		estàs utilitzant un teclat especial (nacional) o no. Si tens un
		teclat US/International normal, el què és el més comú, pots
		pitja senzillament &lt;Enter&gt; en aquesta pregunta. Després
		d'això apareixerà la pantalla d'inici de sessió. Inicia-la com 
		<span class="quote">“<span class="quote">root	</span>”</span>, no et demanarà contrasenya. Després 
		d'iniciar sessió, s'engega l'interpret i ja pots començar a 
		instal·lar Slackware Linux. Aquest procés s'explica breument en
		aquest capítol.
		 
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-install-partitioning"></a>5.2. Particionar un disc dur </h2></div></div></div>
    

    <p>
		Instalar Slackware Linux requereix almenys una partició de Linux,
		a més es recomana crear una partició swap (intercanvi). Per a
		poder crear una partició ha d'haver espai lliure sense particionar
		al disc. Hi ha alguns programes que poden redimensionar particions.
		Per exemple, FIPS pot redimensionar particions FAT. Programes
		comercials com Partition Magic també poden redimensionar altres
		tipus de particions.
      
    </p>

    <p>
		Després de llançar la el CD-ROM Slackware Linux i de iniciar
		sessió tens dos programes a la teua disposició: <span class="command"><strong>fdisk
		</strong></span> i <span class="command"><strong>cfdisk</strong></span>. <span class="command"><strong>cfdisk</strong></span> 
		és el més senzill dels dos perque es controla mitjaçant una 
		interfície de menús. Aquesta secció descriu el programa
		<span class="command"><strong>cfdisk</strong></span>.
		
      
    </p>

    <p>
		Per a particionar el primer disc dur pots, simplement, executar 
		<span class="command"><strong>cfdisk</strong></span>. En cas de que vulgues particionar
		algún altre disc o un disc SCSI, hauràs d'especificar quin disc
		vols particionar (<span class="command"><strong>cfdisk /dev/device</strong></span>). Els
		discs durs ATA s'identifiquen mitjançant la següent nomenclatura:
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hdn</code></html:span>, amb <span class="quote">“<span class="quote">n</span>”</span> reemplaçat
		per un caràcter, per exemple. el <span class="quote">“<span class="quote">mestre primari</span>”</span> 
		es diu <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hda</code></html:span>, l'<span class="quote">“<span class="quote">esclau secundari
		</span>”</span> es diu <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hdd</code></html:span>. Els discs SCSI
		es diuen de la següent manera: <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/sdn</code></html:span>,
		canviant la <span class="quote">“<span class="quote">n</span>”</span> pel caràcter corresponent(el primer
		disc SCSI = a, el quart disc SCSI = d).
		
      
    </p>

    <div class="figure">
<a name="chap-install-partitioning-cfdisk"></a><p class="title"><b>Figure 5.1. La eina de particionat cfdisk</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/cfdisk.png" alt="La eina de particionat cfdisk"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després d'iniciar <span class="command"><strong>cfdisk</strong></span> es mostren les 
		particions existens així com la quantitat d'espai lliure. La
		llista de particions pot ser navegada amb les tecles de fletxa 
		<span class="quote">“<span class="quote">amunt</span>”</span> i fletxa <span class="quote">“<span class="quote">avall</span>”</span>. Baix de tot
		de la pantalla es mostren algunes ordres, que es poden executar
		mitjançant la tecla &lt;Enter&gt;.
		
      
    </p>

    <p>
		Pots crear una partició de Linux seleccionant <span class="quote">“<span class="quote">Free
      Space</span>”</span> (espai lliure) i executant la ordre <span class="quote">“<span class="quote">New</span>”</span>.
      <span class="command"><strong>cfdisk</strong></span> preguntará si el que vols crear és una
      partició primaria o lògica. Es poden crear un màxim de quatre 
      particions primàries i Linux es pot instal·lar tant en particions
      primàries con en lògiques. Si tens pensat intal·lar altres sistemes
      operatius a banda de Slackware Linux que requerisquen particions
      primàries, és una bona idea que instal·les Slackware Linux en un 
      lògica. El tipus de la nova partició es posa automàticament com 
      <span class="quote">“<span class="quote">Linux Native</span>”</span>, així que no és necessari posar-lo.
      
      
    </p>

    <p>
		La creació d'un partició d'intercanvi (swap) involucra els 
		mateixos passos que una partició normal de Linux, només que el
		tipus de la partició s'ha de canviar a <span class="quote">“<span class="quote">Linux Swap</span>”</span>
		després de crear la partició. El tamany recomanat per a la
		partició d'intercanvi dependrà de les teues necessitats. La 
		partició d'intercanvi s'utilitza per a emmagatzemar programes
		si la memòria principal (RAM) està plena. Si tens un disc dur
		d'un tamany raonable és bona idea crear-ne una de 256MB o 512MB,
		el que serà suficient per al funcionament normal. Després de
		crear la partició, es pot canviar el tipus de partició a 
		<span class="quote">“<span class="quote">Linux Swap</span>”</span> seleccionant la ordre <span class="quote">“<span class="quote">Type</span>”</span>,
		<span class="command"><strong>cfdisk</strong></span> et demanarà el nombre de tipus. A les
		partitions <span class="quote">“<span class="quote">Linux Swap</span>”</span> els correspon el tipus 
		número 82. Normalment el número 82 ja està triat, pel que pots
		seguir endavant pitjant la tecla &lt;Enter&gt;.
      
      
    </p> 

    <p>
		Si estàs satisfet amb el particionament, pots alçar els canvis
		executant la ordre <span class="quote">“<span class="quote">Write</span>”</span>. Aquesta operació s'ha
		de confirmar introduïnt <span class="command"><strong>yes</strong></span> (sí). Després de
		alçar els canvis es pot deixar el <span class="command"><strong>cfdisk</strong></span> amb
		la ordre <span class="command"><strong>Quit</strong></span>. És una bona idea reiniciar
		l'ordinador abans d'iniciar la instal·lació, per a assabentar-nos
		de que els canvis en el particionament estàn actius. Pitja 
		&lt;ctrl&gt; + &lt;alt&gt; + &lt;del&gt; per a t el Linux
		i reiniciar l'ordinador.
      
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-install-installing"></a>5.3. Instal·lant Slackware Linux</h2></div></div></div>
    

    <p>
		L'instal·lador de Slackware Linux s'inicia executant <span class="command"><strong>
		setup</strong></span> a l'interpret del disc d'instal·lació. Setup
		mostrarà un menú amb vàries opcions. Pots veurer una captura de
		pantalla del instal·lador a <a class="xref" href="#chap-install-installing-setup" title="Figure 5.2. La eina setup">Figure 5.2, “La eina setup ”</a>. 
		Es requereixen completar totes les opcions per a fer una 
		instal·lació completa, però una vegada que has començat, el 
		programa et guiará a través d'elles.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-setup"></a><p class="title"><b>Figure 5.2. La eina setup </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/setup.png" alt="La eina setup"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		La primera part de la instal·lació s'anomena <span class="quote">“<span class="quote">ADDSWAP
		</span>”</span>. La eina <span class="command"><strong>setup</strong></span> buscarà una partició
		del tipus <span class="quote">“<span class="quote">Linux Swap</span>”</span> i et preguntarà si vols 
		formatar-la i activar-la (mira la figura <a class="xref" href="#chap-install-installing-addswap" title="Figure 5.3. Preparant la partició d'intercanvi">Figure 5.3, “Preparant la partició d'intercanvi ”</a>). Normalment pots,
		senzillament, contestar <span class="quote">“<span class="quote">Yes</span>”</span>.
      
      
    </p>

    <div class="figure">
<a name="chap-install-installing-addswap"></a><p class="title"><b>Figure 5.3. Preparant la partició d'intercanvi </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/addswap.png" alt="Preparant la partició d'intercanvi"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després de preparar l'espai d'intercanvi, es llança el  menú 
		<span class="quote">“<span class="quote">TARGET</span>”</span>, que es pot veurer a <a class="xref" href="#chap-install-installing-partselect" title="Figure 5.4. Seleccionant una partició a inicialitzar">Figure 5.4, “Seleccionant una partició a inicialitzar ”</a>. Este apartat 
		acostuma a inicialitzar les particions de Slackware Linux. Setup 
		mostrarà totes les particions tipus <span class="quote">“<span class="quote">Linux Native</span>”</span>.
      
      
    </p>

    <div class="figure">
<a name="chap-install-installing-partselect"></a><p class="title"><b>Figure 5.4. Seleccionant una partició a inicialitzar </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/partselect.png" alt="Seleccionant una partició a inicialitzar"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després de triar una partició, la eina setup et preguntarà si 
		vols formatar la partició o no, i en eixe cas, si vols comprovar
		si el disc conté sectors defectuosos. (<a class="xref" href="#chap-install-installing-fscheck" title="Figure 5.5. Formatant la partició">Figure 5.5, “Formatant la partició ”</a>). La comprovació de
		disc pot prendre molt de temps.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-fscheck"></a><p class="title"><b>Figure 5.5. Formatant la partició </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/fscheck.png" alt="Formatant la partició"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després de triar que volem formatar una partició, es pot
		especificar quin sistema de fitxers s'hauria d'utilitzar. 
		Normalment, pots triar entre ext2, ext3 i reiserfs.	Ext2 va ser 
		el sistema de fitxers estàndard durant molt anys, pero no 
		suportava journaling (registres diaris). Un diari (journal) és
		un fitxer especial o una àrea de una partició en què es registren
		totes les operacions del sistema de fitxers. Quan el sistema
		té un accident, el sistema de fitxers es pot arreglar ràpidament,
		perque el núcli pot utilitzar el diari per a veurer quines 
		operacions de disc s'havien realitzat. Ext3 és el mateix 
		sistema de fitxers que ext2, però afig journaling. Reiserfs és 
		un sistema de fitxers que també	proporciona journaling, però 
		utilitza arbres balancejats, el que fa que moltes operacions
		sobre disc siguen més ràpides que amb Ext2 o Ext3, especialment
		al treballar amb molts fitxers menuts. El defecte és que al ser
		més nou, pot ser una miqueta més inestable.
		
      
    </p>

    <div class="figure">
<a name="chap-install-installing-filesystem"></a><p class="title"><b>Figure 5.6. Triant el tipus de sistema de fitxers </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/filesystem.png" alt="Triant el tipus de sistema de fitxers"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		La primer partició inicialitzada es munta automàticament com 
		la partició arrel (/). Per a altres particions, es pot triar
		el punt de muntatge després de la inicialització. Tú pots, 
		per exemple, crear particions separades per a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span>,
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var</code></html:span>, <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/tmp</code></html:span>,
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home</code></html:span> i <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr</code></html:span>. Açò
		proporciona una protecció extra contra accidents. Com 
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span> es canvia molt rarament després de la 
		instal·lació, si crees estes particions, la probabilitat de que
		estiguen enmig d'una operació d'escriptura durant un accident és
		molt menor. A més, és més segur crear un sistema de fitxers
		distint per a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home</code></html:span> ja que si un programa
		té una vulnerabilitat, un usuari podria crear un enllaç dur al
		binari d'eixe programa sempre i quan el directori 
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home</code></html:span> està en el mateix sistema de fitxers 
		que les carpeta <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/{s}bin</code></html:span>, 
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/{s}bin</code></html:span>, o <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/local/{s}bin
		</code></html:span>. En aquest cas, l'usuari continuarà podent accedir 
		al vell i vulnerable binari després de que el programa siga
		actualitzat.
      
    </p>

    <p>
		El següent pas és seleccionar el medi origen (<a class="xref" href="#chap-install-installing-medium" title="Figure 5.7. Triant el medi origen">Figure 5.7, “Triant el medi origen ”</a>). Este diàleg t'ofereix
      vàries opcions, com la instal·lació de Slackware Linux des d'un 
      CD-ROM o via NFS. La primera opció és la més comuna alhora 
      d'instal·lar Slackware Linux, pel que és el mètode que veurem ací.
      Després de triar <span class="quote">“<span class="quote">CD-ROM</span>”</span> se't demanarà si vols que 
      setup localitze el CD-ROM (<span class="quote">“<span class="quote">Auto</span>”</span>) o si per contra
      vols triar el dispositiu tú mateix (<span class="quote">“<span class="quote">Manual</span>”</span>). Si 
      tries <span class="quote">“<span class="quote">Manual</span>”</span> la eina setup et mostrarà una llista
      de dispositius, tria el dispositiu que conté el CD-ROM de Slackware
      Linux.
      
      
    </p> 

    <div class="figure">
<a name="chap-install-installing-medium"></a><p class="title"><b>Figure 5.7. Triant el medi origen </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/medium.png" alt="Triant el medi origen"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després de triar un origen de la instal·lació, la eina setup
		et demanarà de quins conjunt de discs (series) vols instal·lar 
		paquets (<a class="xref" href="#chap-install-installing-disksets" title="Figure 5.8. Triant els conjunts de discs">Figure 5.8, “Triant els conjunts de discs”</a>). 
		Es llista una xicoteta descripció de capa conjunt de discs.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-disksets"></a><p class="title"><b>Figure 5.8. Triant els conjunts de discs</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/disksets.png" alt="Triant els conjunts de discs"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Pràcticament ha arribat l'hora de començar la instal·lació real. 
		La següent pantalla et demana què t'agradaria instalar. Les 
		opcions	més evidents són <span class="quote">“<span class="quote">full</span>”</span>, <span class="quote">“<span class="quote">menu</span>”</span>
		o <span class="quote">“<span class="quote">expert</span>”</span>. Si es selecciona <span class="quote">“<span class="quote">full</span>”</span> 
		instal·larà tots els paquets continguts als conjunts de discs
		seleccionats. Esta és la manera més senzilla d'instal·lar 
		Slackware Linux. L'inconvenient d'aquesta tria és que pot 
		ocupar molt d'espai de disc. La opció <span class="quote">“<span class="quote">menu</span>”</span>
		preguntarà quins paquets vols instal·lar de cada conjunt de
		discs. La opció <span class="quote">“<span class="quote">expert</span>”</span> és pràcticament igual que
		<span class="quote">“<span class="quote">menu</span>”</span>, només que et permet deseleccionar alguns 
		paquets realment importants del conjunt de discs <span class="quote">“<span class="quote">a</span>”</span>.
		
      
    </p>

    <p>
		Una vegada s'ha completat la instal·lació l'eina setup et
		permetrà configurar algunes parts del sistema. El primer diàleg
		et demanarà des d'on vodries instal·lar el núcli (mira <a class="xref" href="#chap-install-installing-installkernel" title="Figure 5.9. Instal·lant el núcli">Figure 5.9, “Instal·lant el núcli”</a>). Normalment
		és una bona idea instal·lar el núcli des d'el CD-ROM de 
		Slackware Linux, açò seleccionarà el núcli amb el que la vas 
		instal·lar. Pots confirmar açò o triar un altre núcli.
	
		
      
    </p>

    <div class="figure">
<a name="chap-install-installing-installkernel"></a><p class="title"><b>Figure 5.9. Instal·lant el núcli</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/kernel.png" alt="Instal·lant el núcli"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		En aquest punt pots escollir fer una disc d'arranc (<a class="xref" href="#chap-install-installing-bootdisk" title="Figure 5.10. Creant un disc d'arranc">Figure 5.10, “Creant un disc d'arranc ”</a>). És una bona idea 
		ja que el pots utilitzar en cas de que la configuració del LILO 
		es llance a perdre.
		
      
    </p>

    <div class="figure">
<a name="chap-install-installing-bootdisk"></a><p class="title"><b>Figure 5.10. Creant un disc d'arranc </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/bootdisk.png" alt="Creant un disc d'arranc"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		El següent diàleg es pot utilitzar per a crear un enllaç, 
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/modem</code></html:span>, que apunta al teu dispositiu
		módem.(<a class="xref" href="#chap-install-installing-modem" title="Figure 5.11. Seleccionant el modem per defecte">Figure 5.11, “Seleccionant el modem per defecte ”</a>). Si no tens un modem
		pots seleccionar <span class="emphasis"><em>no modem</em></span>.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-modem"></a><p class="title"><b>Figure 5.11. Seleccionant el modem per defecte </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/modem.png" alt="Seleccionant el modem per defecte"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		El següent pas és triar si es vol utilitzar hotplug (<a class="xref" href="#chap-install-installing-hotplug" title="Figure 5.12. Habilitant l'endollat en calent">Figure 5.12, “Habilitant l'endollat en calent”</a>). Hotplug s'utilitza
		per a configurar automàticament dispositius endollables USB,
		PCMCIA i PCI. En línies generals, és una bona idea habilitat 
		la connexió en calent (hotplugging), però alguns sistemes poden
		tindre problemes amb ???el sondeig de guions d'endollat en calent.???
		
      The next step is to select whether you would like to use hotplug
      (<a class="xref" href="#chap-install-installing-hotplug" title="Figure 5.12. Habilitant l'endollat en calent">Figure 5.12, “Habilitant l'endollat en calent”</a>).  Hotplug is used for automatically configuring pluggable
      USB, PCMCIA and PCI devices. Generally speaking, it is a good
      idea to enable hotplugging, but some systems may have problems
      with the probing of the hotplug scripts.
    </p>

    <div class="figure">
<a name="chap-install-installing-hotplug"></a><p class="title"><b>Figure 5.12. Habilitant l'endollat en calent</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/hotplug.png" alt="Habilitant l'endollat en calent"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Els passos següents són importants ja que ajuden a instal·lar 
		LILO, el carregador de llançament del Linux. Llevat que tingues
		experiència configurant LILO és una bona idea triar la opció 
		<span class="emphasis"><em>simple</em></span>, la qual intenta configurar LILO 
		automàticament (<a class="xref" href="#chap-install-installing-liloinstall" title="Figure 5.13. Triant el tipus d'instal·lació de LILO">Figure 5.13, “Triant el tipus d'instal·lació de LILO ”</a>).
		
      
    </p>

    <div class="figure">
<a name="chap-install-installing-liloinstall"></a><p class="title"><b>Figure 5.13. Triant el tipus d'instal·lació de LILO </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/lilo.png" alt="Triant el tipus d'instal·lació de LILO"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després d'escollir la opció <span class="emphasis"><em>simple</em></span> la
		utilitat de configuració del LILO et preguntarà si t'agradaria
		utilitzar un framebuffer o no (<a class="xref" href="#chap-install-installing-framebuffer" title="Figure 5.14. Triant la resolució framebuffer">Figure 5.14, “Triant la resolució framebuffer ”</a>). Utilitzar
		un framebuffer et permetrà utilitzar la consola en diferents
		resolucions, amb unes dimensions diferents a la típica de 80x25
		cartàcters. Hi ha gent que utilitza molt la consola que prefereix
		utilitzar un framebuffer perque els permet tindre més text a la
		pantalla. Si no vols una consola framebuffer, o si no estàs segur,
		pots triar <span class="emphasis"><em>estàndard</em></span> ací.
		
      
    </p>

    <div class="figure">
<a name="chap-install-installing-framebuffer"></a><p class="title"><b>Figure 5.14. Triant la resolució framebuffer </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/framebuffer.png" alt="Triant la resolució framebuffer"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després de posar el framebuffer li pots passar paràmetres extra
		al núcli (<a class="xref" href="#chap-install-installing-kernel-param" title="Figure 5.15. Afegint paràmetres al núcli">Figure 5.15, “Afegint paràmetres al núcli”</a>). Açò normalment no és necessari, així que si no vols passar-li
      paràmetre extra pots senzillament, pitjar la tecla &lt;Enter&gt;.
      
      
    </p>

    <div class="figure">
<a name="chap-install-installing-kernel-param"></a><p class="title"><b>Figure 5.15. Afegint paràmetres al núcli</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/kernel-param.png" alt="Afegint paràmetres al núcli"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		L'últim pas de la configuració del LILO consisteix a seleccionar
		on volem que s'instal·le 
		(<a class="xref" href="#chap-install-installing-lilo-dest" title="Figure 5.16. Escollint on s'hauria d'instal·lar el LILO">Figure 5.16, “Escollint on s'hauria d'instal·lar el LILO ”</a>). l'MBR és
		el registre mestre de llançament (Master Boot Record), el 
		registre principal de llançament en PCs. Utilitza aquesta opció 
		si vols utilitzar Slackware Linux com l'únic Sistema Operatiu, o
		si vols emprar el LILO per a llançar altres sistemes operatius. 
		La opció <span class="emphasis"><em>Root</em></span> instal·larà LILO en el registre
		de llançament de la partició <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span> de Slackware
		Linux. Utilitza aquesta opció si utilitzes un altre carregador de
		llançament.
		
      
    </p>

    <div class="figure">
<a name="chap-install-installing-lilo-dest"></a><p class="title"><b>Figure 5.16. Escollint on s'hauria d'instal·lar el LILO </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/lilo-dest.png" alt="Escollint on s'hauria d'instal·lar el LILO"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Ara se't demanarà que configures el ratolí. Tria el tipus de
		ratolí al diàleg que apareix (<a class="xref" href="#chap-install-installing-mouse" title="Figure 5.17. Configurant un ratolí">Figure 5.17, “Configurant un ratolí ”</a>).
      
    </p>

    <div class="figure">
<a name="chap-install-installing-mouse"></a><p class="title"><b>Figure 5.17. Configurant un ratolí </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/mouse.png" alt="Configurant un ratolí"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Aleshores se't preguntarà si el programa <span class="command"><strong>gpm</strong></span>
		hauria de carregar-se en l'arranc o no 
		(<a class="xref" href="#chap-install-installing-ask-load-gpm" title="Figure 5.18. Escollint si GPM s'hauria d'iniciar">Figure 5.18, “Escollint si GPM s'hauria d'iniciar”</a>).
		<span class="command"><strong>gpm</strong></span> és un daemon que permet tallar i enganxar
		a la consola.
      
      
    </p>

    <div class="figure">
<a name="chap-install-installing-ask-load-gpm"></a><p class="title"><b>Figure 5.18. Escollint si GPM s'hauria d'iniciar</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/ask-load-gpm.png" alt="Escollint si GPM s'hauria d'iniciar"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		A continuació, amb uns pocs passos més,es configura la
		connectivitat de xarxa. Açò es un requeriment en pràcticament 
		tots els sistemes en xarxa. La instal·lació de Slackware Linux
		et preguntarà si vols configurar-la (<a class="xref" href="#chap-install-installing-ask-configure-network" title="Figure 5.19. Escollint si t'agradaria configurar la connectivatat de xarxa">Figure 5.19, “Escollint si t'agradaria configurar la connectivatat de xarxa
      ”</a>). Si contestes <span class="quote">“<span class="quote">No</span>”</span> pots saltar els passos 
		següents relatius a la xarxa.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-ask-configure-network"></a><p class="title"><b>Figure 5.19. Escollint si t'agradaria configurar la connectivatat de xarxa
      </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/ask-configure-network.png" alt="Escollint si t'agradaria configurar la connectivatat de xarxa"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Ara se't demanarà si vols posar el nom de màquina (<a class="xref" href="#chap-install-installing-hostname" title="Figure 5.20. Posant el nom de host">Figure 5.20, “Posant el nom de host ”</a>). 
		Per favor tin en compte que aquest no és el nom de domini 
		plenament qualificat (FQDN, Fully Qualified Domain Name), només
		la part que representa a l'ordinador (normalment els caràcters
		abans del primer punt en un FQDN).
      
    </p>

    <div class="figure">
<a name="chap-install-installing-hostname"></a><p class="title"><b>Figure 5.20. Posant el nom de host </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/hostname.png" alt="Posant el nom de host"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després de posar el nom del host pots posar la part del domini
		del nom de domini plenament qualificat (FQDN) (<a class="xref" href="#chap-install-installing-domainname" title="Figure 5.21. Posant el nom de domini">Figure 5.21, “Posant el nom de domini ”</a>).
      
      
    </p>

    <div class="figure">
<a name="chap-install-installing-domainname"></a><p class="title"><b>Figure 5.21. Posant el nom de domini </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/domainname.png" alt="Posant el nom de domini"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		La resta de passos per a configurar la xarxa depenen de si els
		nodes de la xarxa estàn configurats per a utilitzar una adreça
		IP estàtica o dinàmica. Algunes xarxes tenen un servidor DHCP 
		que assigna automàticament una adreça IP als nodes en la xarxa.
		Si aquest és el cas, tria <span class="emphasis"><em>DHCP</em></span> durant el 
		pas d'instal·lació 
		(<a class="xref" href="#chap-install-installing-set-ipconfig-type" title="Figure 5.22. Configuració manual o automàtica de l'adreça IP">Figure 5.22, “Configuració manual o automàtica de l'adreça IP
      ”</a>). Quan es selecciona DHCP només se't preguntarà si s'ha 
		d'enviar un nom de màquina al servidor, normalment, pots deixar-ho 
		en blanc. Si utilitzes DHCP pots saltar-te la resta de la
		configuració de xarxa, descrita a continuació.
      
    </p>

    <p>
		Si la xara no té un servidor DHCP pots triar la opció
		<span class="emphasis"><em>static IP</em></span>, que et permetrà posar manualment
		l'adreça IP i la resta de paràmetres relacionats.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-set-ipconfig-type"></a><p class="title"><b>Figure 5.22. Configuració manual o automàtica de l'adreça IP
      </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/set-ipconfig-type.png" alt="Configuració manual o automàtica de l'adreça IP"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		El primer paso en la configuració manual és posar l'adreça IP
		de la primera interfície (eth0) de la màquina (<a class="xref" href="#chap-install-installing-ipaddr" title="Figure 5.23. Posant l'adreça IP">Figure 5.23, “Posant l'adreça IP”</a>).
      
    </p>

    <div class="figure">
<a name="chap-install-installing-ipaddr"></a><p class="title"><b>Figure 5.23. Posant l'adreça IP</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/ipaddr.png" alt="Posant l'adreça IP"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Una vegada posada l'adreça IP seràs preguntat per la màscara de
		subxarxa, que normalment depén de la ????classe???? d'adreça IP
      (<a class="xref" href="#chap-install-installing-netmask" title="Figure 5.24. Posant la màscara de subxarxa">Figure 5.24, “Posant la màscara de subxarxa”</a>).
    </p>

    <div class="figure">
<a name="chap-install-installing-netmask"></a><p class="title"><b>Figure 5.24. Posant la màscara de subxarxa</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/netmask.png" alt="Posant la màscara de subxarxa"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Aleshores se't demanarà que poses l'adreça de la porta d'enllaç
		(gateway) (<a class="xref" href="#chap-install-installing-gateway" title="Figure 5.25. Posant la porta d'enllaç">Figure 5.25, “Posant la porta d'enllaç”</a>).
		La porta d'enllaç és la màquina en la xarxa que proporciona 
		accés a altres xarxes mitjançant l'enrutatge de paquets. Si la 
		teua xarxa no té porta d'enllaç pots, senzillament, colpejar la 
		tecla &lt;ENTER&gt;.
		
      
    </p>

    <div class="figure">
<a name="chap-install-installing-gateway"></a><p class="title"><b>Figure 5.25. Posant la porta d'enllaç</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/gateway.png" alt="Posant la porta d'enllaç"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		El diàleg següent et preguntarà si vols utilitzar un servidor de
		noms (<a class="xref" href="#chap-install-installing-ask-nameserver" title="Figure 5.26. Triant si vols emprar un servidor de noms o no">Figure 5.26, “Triant si vols emprar un servidor de noms o no 
      ”</a>).
		Un servidor de noms és un servidor que pot proporcionar l'adreça
		IP associada a un nom de màquina. Per exemple, si naveges fins a
		<span class="emphasis"><em>www.slackbasics.org</em></span>, el servidor de noms
		<span class="quote">“<span class="quote">convertirà</span>”</span> el nom <span class="emphasis"><em>www.slackbasics.org
		</em></span> a la seua adreça IP corresponent.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-ask-nameserver"></a><p class="title"><b>Figure 5.26. Triant si vols emprar un servidor de noms o no 
      </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/ask-nameserver.png" alt="Triant si vols emprar un servidor de noms o no"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Si vas escollir utilitzar un servidor de noms, se't donarà la oportunitat
		de posar la seua adreça IP (<a class="xref" href="#chap-install-installing-nameserver" title="Figure 5.27. Posant el(s) servidor(s) de noms">Figure 5.27, “Posant el(s) servidor(s) de noms”</a>).
      
    </p>

    <div class="figure">
<a name="chap-install-installing-nameserver"></a><p class="title"><b>Figure 5.27. Posant el(s) servidor(s) de noms</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/nameserver.png" alt="Posant el(s) servidor(s) de noms"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		La última pantalla de configuració de xarxa en mostra un resum
		dels paràmetres triats, oferint-nos la oportunitat de corregir 
		aquells paràmetres que no siguen correctes (<a class="xref" href="#chap-install-installing-network-confirm" title="Figure 5.28. Confirmant els paràmetres de xarxa">Figure 5.28, “Confirmant els paràmetres de xarxa ”</a>).
      
    </p>

    <div class="figure">
<a name="chap-install-installing-network-confirm"></a><p class="title"><b>Figure 5.28. Confirmant els paràmetres de xarxa </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/network-confirm.png" alt="Confirmant els paràmetres de xarxa"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Després de la configuració de xarxa pots posar quins serveis
		s'haurien de iniciar (<a class="xref" href="#chap-install-installing-startup-services" title="Figure 5.29. Habilitant/deshabilitant serveis d'inici">Figure 5.29, “Habilitant/deshabilitant serveis d'inici ”</a>). Pots marcar o desmarcar servicis amb la tecla &lt;SPACE&gt;.
      
      
    </p>

    <div class="figure">
<a name="chap-install-installing-startup-services"></a><p class="title"><b>Figure 5.29. Habilitant/deshabilitant serveis d'inici </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/startup-services.png" alt="Habilitant/deshabilitant serveis d'inici"></div>
    </div>
</div>
<br class="figure-break">

    

    <p>
		Tradicionalment en sistemes tipus UNIX el rellotge del sistema 
		es posa amb la zona horària UTC. Si este és el cas, tria 
		<span class="emphasis"><em>Yes</em></span> al pas següent (<a class="xref" href="#chap-install-installing-ask-clock-utc" title="Figure 5.30. Triant si el rellotge del sistema es posa UTC">Figure 5.30, “Triant si el rellotge del sistema es posa UTC 
      ”</a>). Si a més utilitzes un SO que no siga tipus UNIX en el
		mateix sistema, com Windows, sol ser bona idea escollir 
		<span class="emphasis"><em>No</em></span>, perque alguns sistemes operatius de PC
		no treballen amb dos rellotges separats, un de sistema i un de 
		programari.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-ask-clock-utc"></a><p class="title"><b>Figure 5.30. Triant si el rellotge del sistema es posa UTC 
      </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/ask-clock-utc.png" alt="Triant si el rellotge del sistema es posa UTC"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Aleshores se't donarà la oportunitat de triar la zona horària
		You will then be given the opportunity to select the time zone
		(<a class="xref" href="#chap-install-installing-timezone" title="Figure 5.31. Posnat la zona horària">Figure 5.31, “Posnat la zona horària ”</a>). Açò és especialment important en sistemes que tenen el seu
		rellotge del sistema posat a UTC, ja que si no es selecciona 
		la zona horària correcta el rellotge de programari no coincidirà
		amb l'hora local.
		
      
    </p>

    <div class="figure">
<a name="chap-install-installing-timezone"></a><p class="title"><b>Figure 5.31. Posnat la zona horària </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/timezone.png" alt="Posnat la zona horària"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		Si has instal·lat el Sistema de Finestres X, ara pots posar el 
		gestor de finestres per defecte (<a class="xref" href="#chap-install-installing-defaultwm" title="Figure 5.32. Escollint el gestor de finestres per defecte">Figure 5.32, “Escollint el gestor de finestres per defecte 
      ”</a>). La funcionalitat més senzilla d'un gestor de finestres és 
		proporcionar una gestió bàsica de finestres, com barres de títol,
		però algunes opcions, com KDE, proporcionen un entorn d'escriptori
		complet.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-defaultwm"></a><p class="title"><b>Figure 5.32. Escollint el gestor de finestres per defecte 
      </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/defaultwm.png" alt="Escollint el gestor de finestres per defecte"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		L'últim pas és posar la contrasenya de root (<a class="xref" href="#chap-install-installing-rootpasswd" title="Figure 5.33. Posant la contrasenya de root">Figure 5.33, “Posant la contrasenya de root”</a>).
      Setup et demanarà si t'agradaria posar una contrasenya o no. No hi
      ha cap raó per a fer açò, i sense una contrasenya de root el teu
      sistema és perillosament insegur.
      
    </p>

    <div class="figure">
<a name="chap-install-installing-rootpasswd"></a><p class="title"><b>Figure 5.33. Posant la contrasenya de root</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/rootpasswd.png" alt="Posant la contrasenya de root"></div>
    </div>
</div>
<br class="figure-break">

    <p>
		En aquest punt ja has completat la instal·lació de Slackware Linux.
		Ara pots reiniciar el sistema per a iniciar el teu recentment 
		instal·lat sistema Slackware Linux. No ha sigut difícil, 
		no és així? ;)
      
    </p>

    <div class="figure">
<a name="chap-install-installing-finished"></a><p class="title"><b>Figure 5.34. Finalitzat</b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/finished.png" alt="Finalitzat"></div>
    </div>
</div>
<br class="figure-break">
  </div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="getstarted-custominstall"></a>Chapter 6. Custom installation</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#getstarted-custominstall-partition">6.1. Partitioning a hard disk</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-initfs">6.2. Initializing and mounting filesystems</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-packages">6.3. Installing packages</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-config">6.4. Post-install configuration</a></span></dt>
<dt><span class="sect1"><a href="#getstarted-custominstall-script">6.5. Automated installation script</a></span></dt>
</dl>
</div>
<p>
    Sometimes you may want to do a custom installation of Slackware Linux,
    for example to get better understanding of how GNU/Linux systems work,
    or to prepare an automatic installation script. This chapter outlines
    the steps that are required to install Slackware Linux manually. A
    sample installation script is also provided in <a class="xref" href="#getstarted-custominstall-script" title="6.5. Automated installation script">Section 6.5, “Automated installation script”</a>.
  </p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="getstarted-custominstall-partition"></a>6.1. Partitioning a hard disk</h2></div></div></div>
<p>
      If you have performed a normal installation, you should not
      have any problems partitioning a disk. You can use the
      <span class="command"><strong>fdisk</strong></span> and <span class="command"><strong>cfdisk</strong></span>
      commands to partition disks. If you are scripting the
      installation of Slackware Linux it is useful to know that
      you can pipe <span class="command"><strong>fdisk</strong></span> commands to
      <span class="command"><strong>fdisk</strong></span>. For example:
    </p>
<pre class="screen">
# <span class="command"><strong>fdisk /dev/hda &lt;&lt; EOF
n
p
1

+10000M
n
p
2

+512M
t
2
82
w
EOF</strong></span>
    </pre>
<p>
      These commands create a primary Linux partition of 10000MB, and
      a primary Linux swap partition of 512MB. You could store the
      <span class="command"><strong>fdisk</strong></span> commands in different disk profiles,
      and use one of the profiles based on the specific deployment
      (e.g.  the disk size). For example:
    </p>
<pre class="screen">
# <span class="command"><strong>cat /usr/share/fdisk-profiles/smalldisk | fdisk</strong></span>
    </pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="getstarted-custominstall-initfs"></a>6.2. Initializing and mounting filesystems</h2></div></div></div>
<p>
      After making at least a swap and a Linux partition, you can
      initialize the filesystem and swap space and make use of this
      storage. On systems that are short on memory, you should initialize,
      and use swap first. We will use the partition layout used in
      the partitioning example listed above in the following examples.
      To set up and use swap, execute:
    </p>
<pre class="screen">
# <span class="command"><strong>mkswap /dev/hda2</strong></span>
# <span class="command"><strong>swapon /dev/hda2</strong></span>
    </pre>
<p>
      The meaning of these commands is quite obvious. <span class="command"><strong>mkswap</strong></span>
      initializes the swap space, and <span class="command"><strong>swapon</strong></span> puts it to
      use. You will only have to execute <span class="command"><strong>mkswap</strong></span> once,
      but <span class="command"><strong>swapon</strong></span> has to be executed during every system
      boot. This can be done automatically by adding an entry for the
      swap partition to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/fstab</code></html:span>, which we will
      do during a later step. 
    </p>
<p>
      For now, it is important to initialize the target partitions. This
      can be done with the <span class="command"><strong>mkfs</strong></span> command. You can
      specify which filesystem should be used by adding the <em class="parameter"><code>-t</code></em> parameter. <span class="command"><strong>mkfs</strong></span>
      will automatically invoke a <span class="command"><strong>mkfs.filesystem</strong></span>
      command based on the filesystem that you have chosen. Be aware that
      the filesystems that can be used depends on the installation
      kernel that you have booted. If you have booted the
      <span class="emphasis"><em>bare.i</em></span> kernel, you can use the
      <span class="emphasis"><em>ext2</em></span>, <span class="emphasis"><em>ext3</em></span> and
      <span class="emphasis"><em>reiserfs</em></span> filesystems.
    </p>
<p>
      To initialize an <span class="emphasis"><em>ext3</em></span> filesystem, and mount it,
      you should execute the following commands:
    </p>
<pre class="screen">
# <span class="command"><strong>mkfs -t ext3 /dev/hda1</strong></span>
# <span class="command"><strong>mount /dev/hda1 /mnt</strong></span>
    </pre>
<p>
      If you have made separate partitions for certain directories
      in the root filesystem, e.g. <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home</code></html:span>, you
      can also initialize them and mount them at this point. For
      example:
    </p>
<pre class="screen">
# <span class="command"><strong>mkfs -t ext3 /dev/hda2</strong></span>
# <span class="command"><strong>mkdir /mnt/home</strong></span>
# <span class="command"><strong>mount /dev/hda2 /mnt/home</strong></span>
    </pre>
<p>
      Finally, you will have to mount your source medium. If you use
      a CD-ROM, this is easy. Suppose that <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hdc</code></html:span>
      is the CD-ROM device file, you can mount the CD-ROM with:
    </p>
<pre class="screen">
# <span class="command"><strong>mount /dev/hdc /var/log/mount</strong></span>
    </pre>
<p>
      Using NFS as the installation medium requires some more steps.
      First of all, you will have to load the network disk.
      You can do this by running the <span class="command"><strong>network</strong></span>
      command and inserting a network disk. You can also load
      this disk from another medium, for example from an USB memory stick.
      Suppose that you have mounted a USB memory stick on /var/log/mount,
      you can load the network disk with: <span class="command"><strong>network
      /var/log/mount/network.dsk</strong></span>. After loading the network
      disk, you will have to configure the network interface. If the
      NFS server is on the same network, you will only have to assign
      an IP address to the network interface. For example, to use
      the address <span class="emphasis"><em>192.168.2.201</em></span>, you could execute
      the following command:
    </p>
<pre class="screen">
# <span class="command"><strong>ifconfig eth0 192.168.2.201</strong></span>
    </pre>
<p>
      You can then load the portmapper, which is necessary for the
      NFS client to function correctly:
    </p>
<pre class="screen">
# <span class="command"><strong>/sbin/rpc.portmap</strong></span>
    </pre>
<p>
      If the portmapper started correctly, you can mount the
      NFS volume. But, first make sure that you unmount any filesystem
      that you have previously mounted at <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var/log/mount</code></html:span>.
      If no other filesystems are mounted at
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var/log/mount</code></html:span>, you can proceed with mounting
      the NFS volume. Suppose, that you want to mount
      <span class="emphasis"><em>192.168.2.1:/home/pub/slackware-current</em></span>,
      you should issue the following command:
    </p>
<pre class="screen">
# <span class="command"><strong>mount -r -t nfs -o nolock 192.168.2.1:/home/pub/slackware-current /var/log/mount</strong></span>
    </pre>
<p>
      If no errors where printed when the volume was mounted, it should be
      accessible through <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var/log/mount</code></html:span>
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="getstarted-custominstall-packages"></a>6.3. Installing packages</h2></div></div></div>
<p>
      Everything is now set up to start installing packages from the
      installation medium. Since <span class="command"><strong>installpkg</strong></span> is
      available from the installation system, you can use it to
      install Slackware Linux packages. To install packages to the
      target partition(s) mounted on <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt</code></html:span>, add
      the <em class="parameter"><code>-root</code></em> option. The
      following command installs all packages from the source medium:
    </p>
<pre class="screen">
# <span class="command"><strong>installpkg -root /mnt /var/log/mount/slackware/*/*.tgz</strong></span>
    </pre>
<p>
      If you have created tagfiles to define which packages should be
      installed, then you can use them now (tagfiles are described
      in <a class="xref" href="#chap-pkgmgmt-tagfiles" title="17.4. Tagfiles (fitxers d'etiquetes)">Section 17.4, “Tagfiles (fitxers d'etiquetes)”</a>). Suppose that you have
      stored a tagfile for each disk set in
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/share/tagfiles/small-desktop</code></html:span>, you
      can install packages based on the tagfiles in the following
      manner:
    </p>
<pre class="screen">
# <span class="command"><strong>for p in a ap d e f k kde kdei l n t tcl x xap y; do
   installpkg -infobox -root /mnt \
     -tagfile /usr/share/tagfiles/small-desktop/$p/tagfile \
     /var/log/mount/slackware/$p/*.tgz
done</strong></span>
    </pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="getstarted-custominstall-config"></a>6.4. Post-install configuration</h2></div></div></div>
<p>
      The next sections describe the bare minimum of configuration that is
      necessary to get a running system.
    </p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="getstarted-custominstall-config-fstab"></a>6.4.1. fstab</h3></div></div></div>
<p>
        One of the necessary configuration steps is to create a <span class="command"><strong>fstab</strong></span>
        file, so that the system can look up what partitions or volumes have
        to be mounted. The format of the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/fstab</code></html:span> file
        is described in <a class="xref" href="#basics-filesystem-mounting-fstab" title="8.8.4. The fstab file">Section 8.8.4, “The fstab file”</a>.
        As a bare minimum you will have to add entries for the
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span> filesystem, the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/proc</code></html:span>
        pseudo-filesystem, the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">devpts</code></html:span> pseudo-filesystem,
        and the swap partition.
      </p>
<p>
        With the sample partitioning used earlier in this chapter, you
        could create a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/fstab</code></html:span> like this:
      </p>
<pre class="screen">
# <span class="command"><strong> cat &gt; /mnt/etc/fstab &lt;&lt; EOF
/dev/hda2	 swap             swap        defaults         0   0
/dev/hda1        /                ext3        defaults         1   1
devpts           /dev/pts         devpts      gid=5,mode=620   0   0
proc             /proc            proc        defaults         0   0
EOF</strong></span>
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="getstarted-custominstall-lilo"></a>6.4.2. LILO</h3></div></div></div>
<p>
        To make the system bootable you will have to configure and install
        the Linux Loader (LILO). The configuration of LILO is covered in
        <a class="xref" href="#chap-init-lilo" title="19.1. The bootloader">Section 19.1, “The bootloader”</a>. For this section we will
        just show a sample LILO configuration, that can be used with
        the partition layout described in this chapter. The first step
        is to create the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/lilo.conf</code></html:span> file:
      </p>
<pre class="screen">
# <span class="command"><strong>cat &gt; /mnt/etc/lilo.conf &lt;&lt; EOF
boot = /dev/hda
vga = normal
timeout = 50
image = /boot/vmlinuz
	root = /dev/hda1
	label = Slackware
	read-only
EOF</strong></span>
      </pre>
<p>
        You can then install LILO with <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt</code></html:span> as the
        LILO root. With <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt</code></html:span> set as the root,
        LILO will use <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/lilo.conf</code></html:span> from the target
        partition:
      </p>
<pre class="screen">
# <span class="command"><strong>lilo -r /mnt</strong></span>
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="getstarted-custominstall-config-network"></a>6.4.3. Networking</h3></div></div></div>
<p>
        The configuration of networking in Slackware Linux is covered in
        <a class="xref" href="#sysadmin-netconfig" title="Chapter 22. Networking configuration">Chapter 22, <i>Networking configuration</i></a>. This section will cover
        one example of a host that will use DHCP to get an IP address.
      </p>
<p>
        The <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/networks</code></html:span> file contains information
        about known Internet networks. Because we will get network
        information via DHCP, we will just use <span class="emphasis"><em>127.0.0.1</em></span>
        as the local network.
      </p>
<pre class="screen">
# <span class="command"><strong>cat &gt; /mnt/etc/networks &lt;&lt; EOF
loopback        127.0.0.0
localnet        127.0.0.0
EOF</strong></span>
      </pre>
<p>
        Although we will get a hostname via DHCP, we will still set up
        a temporary hostname:
      </p>
<pre class="screen">
# <span class="command"><strong>cat &gt; /mnt/etc/HOSTNAME &lt;&lt; EOF
sugaree.example.net
EOF</strong></span>
      </pre>
<p>
        Now that the hostname is configured, the hostname and 
        <span class="emphasis"><em>localhost</em></span> should also be made
        resolvable, by creating a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts</code></html:span>
        database:
      </p>
<pre class="screen">
# <span class="command"><strong>cat &gt; /mnt/etc/hosts &lt;&lt; EOF
127.0.0.1	localhost
127.0.0.1	sugaree.example.net	sugaree	
EOF</strong></span>
      </pre>
<p>
        We do not have to create a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/resolv.conf</code></html:span>,
        since it will be created automatically by <span class="command"><strong>dhcpcd</strong></span>,
        the DHCP client. So, finally, we can set up the interface
        in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.inet1.conf</code></html:span>:
      </p>
<pre class="screen">
# <span class="command"><strong>cat &gt; /mnt/etc/rc.d/rc.inet1.conf &lt;&lt; EOF
IPADDR[0]=""
NETMASK[0]=""
USE_DHCP[0]="yes"
DHCP_HOSTNAME[0]=""
EOF</strong></span>
      </pre>
<p>
	You may want to make a backup of the old
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">rc.inet1.conf</code></html:span> file first, because it
	contains many useful comments. Or you can use
	<span class="command"><strong>sed</strong></span> to change this specific option:
      </p>
<pre class="screen">
# <span class="command"><strong>sed -i 's/USE_DHCP\[0\]=""/USE_DHCP[0]="yes"/' \
   /mnt/etc/rc.d/rc.inet1.conf</strong></span>
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="getstarted-custominstall-config-init"></a>6.4.4. Tuning initialization scripts</h3></div></div></div>
<p>
        Depending on the purpose of the system that is being installed,
        it should be decided which initialization scripts should be started.
        The number of services that are available depends on what packages
        you have installed. You can get get a list of available scripts
        with <span class="command"><strong>ls</strong></span>:
      </p>
<pre class="screen">
# <span class="command"><strong>ls -l /mnt/etc/rc.d/rc.*</strong></span>
      </pre>
<p>
        If the executable bits are set on a script, it will be started,
        otherwise it will not. Obviously you should keep essential scripts
        executable, including the runlevel-specific scripts. You can set
        the executable bit on a script with:
      </p>
<pre class="screen">
# <span class="command"><strong>chmod +x /mnt/etc/rc.d/rc.scriptname</strong></span>
      </pre>
<p>
        Or remove it with:
      </p>
<pre class="screen">
# <span class="command"><strong>chmod -x /mnt/etc/rc.d/rc.scriptname</strong></span>
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="getstarted-custominstall-config-ldconfig"></a>6.4.5. Configuring the dynamic linker run-time bindings</h3></div></div></div>
<p>
        GNU/Linux uses a cache for loading dynamic libraries. Besides that
        many programs rely on generic version numbers of libraries
        (e.g. <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/lib/libgtk-x11-2.0.so</code></html:span>, rather
        than <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/lib/libgtk-x11-2.0.so.0.600.8</code></html:span>).
        The cache and library symlinks can be updated in one
        <span class="command"><strong>ldconfig</strong></span> run:
      </p>
<pre class="screen">
# <span class="command"><strong>chroot /mnt /sbin/ldconfig</strong></span>
      </pre>
<p>
        You may not know the <span class="command"><strong>chroot</strong></span> command; it is
        a command that executes a command with a different root than
        the active root. In this example the root directory is changed
        to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt</code></html:span>, and from there <span class="command"><strong>chroot</strong></span>
        runs <span class="command"><strong>/sbin/ldconfig</strong></span> binary. After the command has
        finished the system will return to the shell, which uses the original
        root. To use <span class="command"><strong>chroot</strong></span> with other commands this
        <span class="command"><strong>ldconfig</strong></span> command has to be executed once first,
        because without initializing the dynamic linker run-time bindings
        most commands will not execute, due to unresolvable library
        dependencies.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="getstarted-custominstall-config-rootpasswd"></a>6.4.6. Setting the root password</h3></div></div></div>
<p>
        Now that the dynamic library cache and links are set up, you
        can execute commands on the installed system. We will make use
        of this to set the <span class="emphasis"><em>root</em></span> password.  The
        <span class="command"><strong>passwd</strong></span> command can be used to set the
        password for an existing user (the <span class="emphasis"><em>root</em></span>
        user is part of the initial <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/passwd</code></html:span>
        file). We will use the <span class="command"><strong>chroot</strong></span> command again
        to execute the command on the target partition:
      </p>
<pre class="screen">
# <span class="command"><strong>chroot /mnt /usr/bin/passwd root</strong></span>
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="getstarted-custominstall-config-timezone"></a>6.4.7. Setting the timezone</h3></div></div></div>
<p>
        On UNIX-like systems it is important to set the timezone correctly,
        because it is used by various parts of the system. For instance,
        the timezone is used by NTP to synchronize the system time correctly,
        or by different networking programs to compute the time difference
        between a client and a server. On Slackware Linux the timezone can be
        set by linking <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/localtime</code></html:span> to a timezone file.
        You can find the timezone for your region by browsing the
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt/usr/share/zoneinfo</code></html:span> directory.
        Most timezones can be found in the subdirectories of their
        respective regions. For example to use
        <span class="emphasis"><em>Europe/Amsterdam</em></span> as the timezone, you can
        execute the following commands:
      </p>
<pre class="screen">
# <span class="command"><strong>cd /mnt</strong></span>
# <span class="command"><strong>rm -rf etc/localtime</strong></span>
# <span class="command"><strong>ln -sf /usr/share/zoneinfo/Europe/Amsterdam etc/localtime</strong></span>
      </pre>
<p>
        After setting the time zone, programs still do not know whether
        the hardware clock is set to the local time, or to the Coordinated
        Universal Time (UTC) standard. If you use another operating system
        on the same machine that does not use UTC it is best to set the
        hardware clock to the local time. On UNIX-like systems it is a
        custom to set the system time to UTC. You can set what time the
        system clock uses, by creating the file
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hardwareclock</code></html:span>, and putting the word
        <span class="emphasis"><em>localtime</em></span> in it if your clock is set to the
        local time, or <span class="emphasis"><em>UTC</em></span> when it is set to UTC.
        For example, to use UTC, you can create
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hardwareclock</code></html:span> in the following manner:
      </p>
<pre class="screen">
# <span class="command"><strong>echo "UTC" &gt; /mnt/etc/hardwareclock</strong></span>
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="getstarted-custominstall-fonts"></a>6.4.8. Creating the X11 font cache</h3></div></div></div>
<p>
        If you are going to use X11, you will have to initialize the
        font cache for TrueType and Type1 fonts. This can be done
        with the <span class="command"><strong>fc-cache</strong></span> command:
      </p>
<pre class="screen">
# <span class="command"><strong>chroot /mnt /usr/bin/fc-cache</strong></span>
      </pre>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="getstarted-custominstall-script"></a>6.5. Automated installation script</h2></div></div></div>
<p>
      It is easy to combine the steps of a custom installation into
      one script, which performs the custom steps automatically. This is ideal
      for making default server installs or conducting mass roll-outs of
      Linux clients. This sections contains a sample script that was
      written by William Park. It is easy to add an installation script
      to the Slackware Linux medium, especially if you use an installation
      CD-ROM or boot the installation system from an USB flash drive.
    </p>
<p>
      The installation system is stored in one compressed image file,
      that is available on the distribution medium as
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">isolinux/initrd.img</code></html:span>. You can make a copy
      of this image to your hard disk, and decompress it with
      <span class="command"><strong>gunzip</strong></span>:
    </p>
<pre class="screen">
# <span class="command"><strong>mv initrd.img initrd.img.gz</strong></span>
# <span class="command"><strong>gunzip initrd.img.gz</strong></span>
    </pre>
<p>
      After decompressing the image, you can mount the file as
      a disk, using the loopback device:
    </p>
<pre class="screen">
# <span class="command"><strong>mount -o loop initrd.img /mnt/hd</strong></span>
    </pre>
<p>
      You can now add a script to the initrd file by adding it to
      the directory structure that is available under the mount point.
      After making the necessary changes, you can unmount the
      filesystem and compress it:
    </p>
<pre class="screen">
# <span class="command"><strong>umount /mnt/hd</strong></span>
# <span class="command"><strong>gzip initd.img</strong></span>
# <span class="command"><strong>mv initrd.img.gz initrd.img</strong></span>
    </pre>
<p>
      You can then put the new <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">initrd.img</code></html:span> file on
      the installation medium, and test the script.
    </p>
<pre class="programlisting">
#! /bin/sh
# Copyright (c) 2003-2005 by William Park &lt;opengeometry@yahoo.ca&gt;.
# All rights reserved.
#
# Usage: slackware-install.sh

rm_ln ()		# Usage: rm_ln from to
{
	rm -rf $2; ln -sf $1 $2
}


###############################################################################
echo "Partitioning harddisk..."

(   echo -ne "n\np\n1\n\n+1000M\n"	# /dev/hda1 --&gt; 1GB swap
	echo -ne "n\np\n2\n\n+6000M\n"	# /dev/hda2 --&gt; 6GB /
	echo -ne "t\n1\n82\nw\n"
) | fdisk /dev/hda

mkswap /dev/hda1		# swap
swapon /dev/hda1

mke2fs -c /dev/hda2		# /
mount /dev/hda2 /mnt


###############################################################################
echo "Installing packages..."

mount -t iso9660 /dev/hdc /cdrom	# actually, /var/log/mount
cd /cdrom/slackware
for p in [a-z]*; do		# a, ap, ..., y
	installpkg -root /mnt -priority ADD $p/*.tgz
done

cd /mnt


###############################################################################
echo "Configuring /dev/* stuffs..."

rm_ln psaux dev/mouse		# or, 'input/mice' for usb mouse
rm_ln ttyS0 dev/modem
rm_ln hdc dev/cdrom
rm_ln hdc dev/dvd


###############################################################################
echo "Configuring /etc/* stuffs..."

cat &gt; etc/fstab &lt;&lt; EOF
/dev/hda1   swap         swap     defaults         0  0
/dev/hda2   /            ext2     defaults         1  1
devpts      /dev/pts     devpts   gid=5,mode=620   0  0
proc        /proc        proc     defaults         0  0
#
/dev/cdrom  /mnt/cdrom   iso9660  noauto,owner,ro  0  0
/dev/fd0    /mnt/floppy  auto     noauto,owner     0  0
tmpfs       /dev/shm     tmpfs    noauto           0  0
EOF

cat &gt; etc/networks &lt;&lt; EOF
loopback	127.0.0.0
localnet	192.168.1.0
EOF
cat &gt; etc/hosts &lt;&lt; EOF
127.0.0.1	localhost
192.168.1.1	node1.example.net	node1
EOF
cat &gt; etc/resolv.conf &lt;&lt; EOF
search example.net
nameserver 127.0.0.1
EOF
cat &gt; etc/HOSTNAME &lt;&lt; EOF
node1.example.net
EOF

## setup.05.fontconfig
chroot . /sbin/ldconfig		# must be run before other program
chroot . /usr/X11R6/bin/fc-cache

chroot . /usr/bin/passwd root

## setup.06.scrollkeeper
chroot . /usr/bin/scrollkeeper-update

## setup.timeconfig
rm_ln /usr/share/zoneinfo/Canada/Eastern  etc/localtime
cat &gt; etc/hardwareclock &lt;&lt; EOF
localtime
EOF

## setup.liloconfig
cat &gt; etc/lilo.conf &lt;&lt; EOF
boot=/dev/hda
delay=100
vga=normal	# 80x25 char
# VESA framebuffer console:
#   pixel	char	8bit	15bit	16bit	24bit
#   -----	----	----	-----	-----	-----
#   1600x1200		796	797	798	799
#   1280x1024	160x64	775	793	794	795
#   1024x768	128x48	773	790	791	792
#   800x600	100x37	771	787	788	789
#   640x480	80x30	769	784	785	786
image=/boot/vmlinuz		# Linux
	root=/dev/hda2
	label=bare.i
	read-only
# other=/dev/hda1		# Windows
#     label=win
#     table=/dev/hda
EOF
lilo -r .

## setup.xwmconfig
rm_ln xinitrc.fvwm95  etc/X11/xinit/xinitrc


###############################################################################
echo "Configuring /etc/rc.d/rc.* stuffs..."

cat &gt; etc/rc.d/rc.keymap &lt;&lt; EOF
#! /bin/sh
[ -x /usr/bin/loadkeys ] &amp;&amp; /usr/bin/loadkeys us.map
EOF
chmod -x etc/rc.d/rc.keymap

## setup.mouse
cat &gt; etc/rc.d/rc.gpm &lt;&lt; 'EOF'
#! /bin/sh
case $1 in
	stop)
	    echo "Stopping gpm..."
	    /usr/sbin/gpm -k
	    ;;
	restart)
	    echo "Restarting gpm..."
	    /usr/sbin/gpm -k
	    sleep 1
	    /usr/sbin/gpm -m /dev/mouse -t ps2
	    ;;
	start)
	    echo "Starting gpm..."
	    /usr/sbin/gpm -m /dev/mouse -t ps2
	    ;;
	*)
	    echo "Usage $0 {start|stop|restart}"
	    ;;
esac
EOF
chmod +x etc/rc.d/rc.gpm

## setup.netconfig
cat &gt; etc/rc.d/rc.inet1.conf &lt;&lt; EOF
IPADDR=(192.168.1.1)		# array variables
NETMASK=(255.255.255.0)
USE_DHCP=()			# "yes" or ""
DHCP_HOSTNAME=()
GATEWAY=""
DEBUG_ETH_UP="no"
EOF

cat &gt; etc/rc.d/rc.netdevice &lt;&lt; EOF
/sbin/modprobe 3c59x
EOF
chmod +x etc/rc.d/rc.netdevice

## setup.setconsolefont
mv etc/rc.d/rc.font{.sample,}
chmod -x etc/rc.d/rc.font

## setup.services
chmod +x etc/rc.d/rc.bind
chmod +x etc/rc.d/rc.hotplug
chmod +x etc/rc.d/rc.inetd
chmod +x etc/rc.d/rc.portmap
chmod +x etc/rc.d/rc.sendmail
#
chmod -x etc/rc.d/rc.atalk
chmod -x etc/rc.d/rc.cups
chmod -x etc/rc.d/rc.httpd
chmod -x etc/rc.d/rc.ip_forward
chmod -x etc/rc.d/rc.lprng
chmod -x etc/rc.d/rc.mysqld
chmod -x etc/rc.d/rc.pcmcia
chmod -x etc/rc.d/rc.samba
chmod -x etc/rc.d/rc.sshd
    </pre>
</div>
</div>
  </div>

  <div class="part">
<div class="titlepage"><div><div><h1 class="title">
<a name="basics"></a>Part II. Conceptes fonamentals de Slackware Linux</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="chapter"><a href="#chap-shell">7. El shell</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-shell-intro">7.1. Introducció </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-executing">7.2. Executant ordres </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-moving">7.3. Anant amunt i avall </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-history">7.4. Historial d'ordres </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-completion">7.5. Autocompletat</a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-wildcards">7.6. Comodins </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-inout">7.7. Redireccions i canonades </a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-filesystem">8. Files and directories</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-filesystem-introduction">8.1. Some theory</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystems-analyzing">8.2. Analyzing files</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-directories">8.3. Working with directories</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-managing">8.4. Managing files and directories</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-permissions">8.5. Permissions</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-finding">8.6. Finding files</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-archives">8.7. Archives</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-mounting">8.8. Mounting filesystems</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-gnupg">8.9. Encrypting and signing files</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-textproc">9. Text processing</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-textproc-simple">9.1. Simple text manipulation</a></span></dt>
<dt><span class="sect1"><a href="#chap-textproc-regexps">9.2. Regular expressions</a></span></dt>
<dt><span class="sect1"><a href="#chap-textproc-grep">9.3. grep</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-procmgmt">10. Process management</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-procmgmt-theory">10.1. Theory</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-analyzing">10.2. Analyzing running processes</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-managing">10.3. Managing processes</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-jobcontrol">10.4. Job control</a></span></dt>
</dl></dd>
</dl>
</div>
    

    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-shell"></a>Chapter 7. El shell</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-shell-intro">7.1. Introducció </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-executing">7.2. Executant ordres </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-moving">7.3. Anant amunt i avall </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-history">7.4. Historial d'ordres </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-completion">7.5. Autocompletat</a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-wildcards">7.6. Comodins </a></span></dt>
<dt><span class="sect1"><a href="#chap-shell-inout">7.7. Redireccions i canonades </a></span></dt>
</dl>
</div>
  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-shell-intro"></a>7.1. Introducció </h2></div></div></div>
    

    <p>
		En aquest capítol vorem l'entorn tradicional de treball als 
		sistemes UNIX: el shell. El shell és un intèrpret què es pot
		utilitzar tant de forma interactiva com no. Quan el shell 
		no s'utilitza de manera interactiva funciona com un simple, però 
		potent llenguatge de guions (scripting language).
      
    </p>

    <p>
		El procediment per a iniciar un shell depén de si utilitzes un 
		inici de sessió gràfic o en mode text. Si estàs iniciant sessió
		en mode text, el shell és iniciat immediatament després de 
		introduir la contrasenya (correcta). Si per contra, utilitzes un
		gestor d'inici de sessió gràfic com KDM, inicia sessió com ho
		faries normalment, i busca al menú d'entorn del teu gestor de 
		finestres una entrada anomenada <span class="quote">“<span class="quote">XTerm</span>”</span>, 
		<span class="quote">“<span class="quote">Terminal</span>”</span> o <span class="quote">“<span class="quote">Konsole</span>”</span>. Xterm és un 
		emulador de terminals, una vegada s'inicia l'emulador de 
		terminal apareix el shell.
		
      
    </p>
		
    <p>
		Abans de continuar, t'hem d'advertir que Slackware Linux 
		no proporciona només un shell. Hi han altres sabors de shell que
		s'han tornat populars amb el temps, el Bourne shell i el C shell.
		En aquest capítol descriurem els shells Bourne que s'ajusten a
		l'estàndard IEEE 1003.1. El shell Bash (Bourne Again Shell) i el 
		ksh (Korn Shell) s'ajusten  bé a aquests estàndards, així què és
		una bona idea utilitzar un d'aquests shells. Pots veurer 
		fàcilment quin shell està corrent el sistema executant la ordre
		<span class="command"><strong>echo $SHELL</strong></span>. Açò és el que el shell Bash
		podria informar:
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>echo $SHELL</code></strong>
/bin/bash
    </pre>
		
    <p>
		Si estàs utilitzant un shell distint, pots canviar el teu shell
		per defecte. Abans de posar un shell diferent, hauràs d'establir
		el camí complet del shell. Ho pots fer mijançant la ordre
		<span class="command"><strong>which</strong></span>. Per exemple:
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>which bash</code></strong>
/bin/bash
$ <strong class="userinput"><code>which ksh</code></strong>
/bin/ksh
    </pre>

    <p>
		En aquest sistema Slackware, el camí complet al shell bash és 
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/bin/bash</code></html:span>, i al shell ksh <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">
		/bin/ksh</code></html:span>. Amb aquesta informació i la ordre 
		<span class="command"><strong>chsh</strong></span> pots canviar el shell per defecte. 
		L'exemple següent posa el bash com a shell per defecte.
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>chsh -s /bin/bash</code></strong>
Changing shell for daniel.
Password:
Shell changed.
    </pre>

    <p>
		El nou shell s'activar després de tancar la sessió amb el shell 
		actual (amb les ordres <span class="command"><strong>logout</strong></span> o 
		<span class="command"><strong>exit</strong></span>), o obrint una nova finestra de terminal
		X si estàs corrent X11.
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-shell-executing"></a>7.2. Executant ordres </h2></div></div></div>
    

    <p>
		Un shell interactiu s'utilitza per a iniciar programes mitjançant
		la execució d'ordres. Hi ha dos tipus d'ordres que un shell pot
		iniciar:
      
    </p>

    <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	<p>
		<span class="emphasis"><em>Ordres incorporades:</em></span> estàn integrades en el 
		shell. Ordres incorporades d'ús comú són: <span class="command"><strong>cd</strong></span>,
		<span class="command"><strong>fg</strong></span>, <span class="command"><strong>bg</strong></span>, i 
		<span class="command"><strong>jobs</strong></span>.
	  
	</p>
      </li>
<li class="listitem">
	<p>
		<span class="emphasis"><em>Ordres externes:</em></span> les ordres externes són
		programes que no formen part del propi programa shell, i que
		s'emmagatzemen a banda al sistema de fitxers. Ordres externes 
		d'ús comú són: <span class="command"><strong>ls</strong></span>, <span class="command"><strong>cat</strong></span>,
		<span class="command"><strong>rm</strong></span>, i <span class="command"><strong>mkdir</strong></span>.
	  
	</p>
      </li>
</ul></div>

    <p>
		Al shell totes les ordres s'executen amb la mateixa sintaxi:
      
    </p>
		
    <pre class="screen">
<span class="command"><strong>nomordre [argument1 argument2 ... argumentn]</strong></span>
    </pre>

    <p>
		El nombre d'arguments és arbitari i es passen sempre a la ordre,
		qui pot decidir què fa amb ells.
      
    </p>

    <p>
		Totes les ordres incorporades poden executarse sempre perque 
		formen part del shell, mentres que les ordres exeternes es poden
		executar pel nom quan el programa està en el camí de búsqueda
		del shell. D'altra manera, hauràs d'especificar el camí al 
		programa. El camí de búsqueda del shell és emmagatzemat a una
		variable anomenada <span class="emphasis"><em>PATH</em></span> (camí). Una 
		variable és una porció de memòria amb nom, el contingut de la 
		qual es pot canviar. Es pot veurer el contingut de la variable
		PATH de la següent manera:
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>echo $PATH</code></strong>
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/daniel/bin
    </pre>

    <p>
		Els camins de directori en la variable <span class="emphasis"><em>PATH</em></span>
		estàn separats per caràcter dos punts (<span class="emphasis"><em>:</em></span>).
		Es pot utilitzar la ordre <span class="command"><strong>which</strong></span> per a 
		comprovar si una ordre donada està en el camí actual del shell.
		Açò es pot fer proporcionant la ordre com a argument a la ordre
		<span class="command"><strong>which</strong></span>. Per exemple:
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>which pwd</code></strong>
/bin/pwd
$ <strong class="userinput"><code>which sysstat</code></strong>
/usr/bin/which: no sysstat in (/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/daniel/bin)
    </pre>

    <p>
		Si un programa no està en el camí, encara pots executarlo 
		introduint el seu camí absolut o relatiu.
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-shell-moving"></a>7.3. Anant amunt i avall </h2></div></div></div>
    

    <p>
		De vegades és necessari saltar entre diverses parts d'una línea
		i modificar-ho quan estàs editant ordres llargues. Tant 
		<span class="command"><strong>bash</strong></span> com <span class="command"><strong>ksh</strong></span>  tenen
		dreceres de teclat per a fer operacions comunes. Hi ha dos modes
		de shell en els que les dreceres són diferents. Aquests modes es
		corresponen en el seu comportament amb dos editors populars per 
		a UNIX, el <span class="command"><strong>vi</strong></span> i l'<span class="command"><strong>emacs</strong></span>.
		En este llibre només cobrirem les pulsacions de tecla tipus
		EMACS. Es pot compovar en quin mode està corrent un shell 
		imprimint la variable <span class="emphasis"><em>SHELLOPTS</em></span>. En el 
		primer exemple s'utilitza el shell en mode <span class="emphasis"><em>emacs
		</em></span> mentres que al segon s'empra el mode <span class="emphasis"><em>vi
		</em></span>. S'identifica el mode buscant la cadena de text
		<span class="emphasis"><em>emacs</em></span> o <span class="emphasis"><em>vi</em></span> en el 
		contingut de la variable.
		
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>echo $SHELLOPTS</code></strong>
braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
    </pre>

    <pre class="screen">
$ <strong class="userinput"><code>echo $SHELLOPTS</code></strong>
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi
    </pre>

    <p>
		Si el teu shell en aquest moment, está utilitzant el mode 
		<span class="emphasis"><em>vi</em></span>, pots canviar al mode <span class="emphasis"><em>emacs
		</em></span> posant la opció <span class="emphasis"><em>emacs</em></span>:
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>set -o emacs</code></strong>
    </pre>

    <p>
		Amb el mode d'edició <span class="emphasis"><em>emacs</em></span> activat, pots
		començar a utilitzar dreceres. Veurem els tres tipus de dreceres:
		dreceres de manipulació de caràcters, de manipulació  de paraules,
		i de manipulació de línies. Més avant en aquest capítol, veurem 
		algunes dreceres que s'utilitzen per a recuperar entrades de 
		l'historial d'ordres.
      
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-shell-moving-char"></a>7.3.1. Manipulant caràcters </h3></div></div></div>
      

      <p>
		  El primer grup de dreceres que empren el caràcter com a unitat
		  lògica, el que significa que permeten manipular operacions
		  sobre caràcters a la línea d'ordres. <a class="xref" href="#chap-shell-moving-char-shortcuts-move" title="Table 7.1. Movent-se per caràcters">Table 7.1, “Movent-se per caràcters ”</a> proporciona
		un resum de les dreceres que s'utilitzen per a moure's a llarg
		d'una línia caràcter a caràcter.
	
      </p>

      <div class="table">
<a name="chap-shell-moving-char-shortcuts-move"></a><p class="title"><b>Table 7.1. Movent-se per caràcters </b></p>
<div class="table-contents">
	

	<table summary="Movent-se per caràcters " border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Tecles</th>
<th>Descripció</th>
</tr></thead>
<tbody>
<tr>
<td>Ctrl-b</td>
<td>Moure un caràcter enrrere </td>
</tr>
<tr>
<td>Ctrl-f</td>
<td>Moure un caràcter endavant </td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
		  Estes dreceres són senzilles i no fan res inesperat. Suposa que
		  has teclejat la següent línia:
	
      </p>

      <pre class="screen">
find ~/music -name '*.ogg' - -print<span class="cursor"> </span>
      </pre>

      <p>
	El cursor estarà al final i et pots moure't al començament de la línia
	mantenint pitjat <span class="emphasis"><em>Ctrl-b</em></span>:
	
      </p>

      <pre class="screen">
<span class="cursor">f</span>ind ~/music - -name '*.ogg' -print
      </pre>

      <p>
		  De la mateixa manera, pots anar enrerre fins al final mantenint
		  pitjat <span class="emphasis"><em>Ctrl-f</em></span>. Hi ha una errada en esta
		  línia, ja que hi ha un guió erroni. Per a esborrar-lo, pots
		  utilitzar una de les següents dreceres.
	
      </p>

      <div class="table">
<a name="chap-shell-moving-char-shortcuts-delete"></a><p class="title"><b>Table 7.2. Esborrant caràcters </b></p>
<div class="table-contents">
	

	<table summary="Esborrant caràcters " border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Tecles</th>
<th>Descripció</th>
</tr></thead>
<tbody>
<tr>
<td>Ctrl-h</td>
<td>Esborra el caràcter abans del cursor. Té el mateix
	      efecte que utilitzar la tecla Backspace en la majoria 
	      d'ordinadors personals.
			</td>
</tr>
<tr>
<td>Ctrl-d</td>
<td>Esborra el caràcter on està el cursor 
	      </td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
		  Es pot eliminar el guió de dos maneres. La primera és moure
		  el cursor fins al guió:
	You can delete the dash in two manners. The first way is to
	move the cursor to the dash:
      </p>

      <pre class="screen">
find ~/music <span class="cursor">-</span> -name '*.ogg' -print
      </pre>

      <p>
		  i prémer <span class="emphasis"><em>Ctrl-d</em></span> dos vegades. Açò esborrarà
		  el guió i l'espai que el segueix.
	
      </p>

      <pre class="screen">
find ~/music <span class="cursor">-</span>name '*.ogg' -print
      </pre>

      <p>
		  Observant el fragment original, l'altra aproximació consisteix
		  a posicionar el cursor a l'espai que hi ha a continuació del 
		  guió:
	
      </p>

      <pre class="screen">
find ~/music -<span class="cursor"> </span> -name '*.ogg' -print
      </pre>

      <p>
		  i prémer <span class="emphasis"><em>Ctrl-h</em></span> dos vegades per a esborrar
		  els dos caràcters precedents, que són el guió i l'espai previ.
		  El resultat serà el mateix, excepte que el curso es mourà:
	
      </p>

      <pre class="screen">
find ~/music<span class="cursor"> </span>-name '*.ogg' -print
      </pre>

      <p>
		  Una de les característiques més maques dels shells més moderns
		  és que pots transposar(interncanviar) caràcters. Açò és de 
		  molta utilitat t'equivoques escrivint i poses dos caràcters 
		  intercanviats. <a class="xref" href="#chap-shell-moving-char-shortcuts-swap" title="Table 7.3. Intercanviant caràcters">Table 7.3, “Intercanviant caràcters ”</a> 
		  llista les dreceres per a transposar caràcters.
	
      </p>

      <div class="table">
<a name="chap-shell-moving-char-shortcuts-swap"></a><p class="title"><b>Table 7.3. Intercanviant caràcters </b></p>
<div class="table-contents">
	

	<table summary="Intercanviant caràcters " border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Tecles</th>
<th>Descripció</th>
</tr></thead>
<tbody><tr>
<td>Ctrl-t</td>
<td>Intercanviar (transposar) el caràcter sobre els que
	      està el cursor i el que hi ha abans. Açò va molt bé a l'hora
	      de corregir ràpidament errors d'escriptura. </td>
</tr></tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
		  Suposa que has escrit la ordre següent:
	
      </p>

      <pre class="screen">
cat myreport.ttx
      </pre>

      <p>
		  La extensió conté un error d'escriptura si pretenies fer
		  <span class="command"><strong>cat</strong></span> <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">myreport.txt</code></html:span>. Açò
		  es pot corregir mitjançant la drecera de transposició de 
		  caràcters. Primer mou-te al segon caràcter del parell de
		  caràcters que estàn canviats.
	
      </p>

      <pre class="screen">
cat myreport.tt<span class="cursor">x</span>
      </pre>

      <p>
		  Aleshores pots prémer <span class="emphasis"><em>Ctrl-t</em></span>, els 
		  caràcters s'intercanviaran, i el cursor es col·locarà darrere
		  d'ells.
	
      </p>

      <pre class="screen">
cat myreport.txt<span class="cursor"> </span>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-shell-moving-word"></a>7.3.2. Manipulació de paraules </h3></div></div></div>
      

      <p>
		  De vegades és tediós moure's a nivell de caràcter. 
		  Afortunadament els shells Korn i Bash poden moure's també al
		  llarg de files i a nivell de paraula. Les paraueles són 
		  seqüències de caràcters separades per un caràcter especial,
		  com un espai.
		  <a class="xref" href="#chap-shell-moving-word-shortcuts-move" title="Table 7.4. Movent-se per paraules">Table 7.4, “Movent-se per paraules ”</a>
		  resumeix les dreceres que es poden utilitzar per a navegar 
		  a través de d'una línia per paraules.
	
      </p>

      <div class="table">
<a name="chap-shell-moving-word-shortcuts-move"></a><p class="title"><b>Table 7.4. Movent-se per paraules </b></p>
<div class="table-contents">
	

	<table summary="Movent-se per paraules " border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Tecles</th>
<th>Descripció</th>
</tr></thead>
<tbody>
<tr>
<td>Esc b</td>
<td>
			  Moure's arrere fins al començament de la paraula actual
			  o l'anterior.
		
	      </td>
</tr>
<tr>
<td>Esc f</td>
<td>
			Moure's avant fins a l'últim caràcter de la actual paraula
			o la pròxima.
		
	      </td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
		  Com pots veurer, les lletres en aquestes dreceres són iguals
		  que les utilitzades per a moure's avant i arrere per caràcters.
		  La lògica del moviment és una miqueta curiosa. Moure's avant
		  col·loca el cursor al final de l'actual paraula, no al primer
		  caràcter de la paraula següent, com podries haver previst.
		  Vejam un exemple senzill. Al começament el cursor és en el 
		  primer caràcter de la línia.
	
      </p>

      <pre class="screen">
<span class="cursor">f</span>ind ~/music -name '*.ogg' -print
      </pre>

      <p>
		  Prémer <span class="emphasis"><em>Esc f</em></span> mourà  el cursor darrere de
		  l'últim caràcter de la primera paraula, què en este cas és 
		  <span class="emphasis"><em>find</em></span>:
	
      </p>

      <pre class="screen">
find<span class="cursor"> </span>~/music -name '*.ogg' -print
      </pre>

      <p>
		  Anant avant una vegada més posará el cursos darrere de 
		  <span class="emphasis"><em>~/music</em></span>:
	
      </p>

      <pre class="screen">
find ~/music<span class="cursor"> </span>-name '*.ogg' -print
      </pre>

      <p>
		  El moviment arrere posa el cursor en el primer caràcter de la
		  paraula actual, o en el primer caràcter de la paraula anterior
		  si el cursor ja es troba en el primer caràcter d'una paraula.
		  Així, moure's arrere una paraula en l'exemple previ posarà el
		  cursor en la primera lletra de <span class="quote">“<span class="quote">music</span>”</span>:
	
      </p>

      <pre class="screen">
find ~/<span class="cursor">m</span>usic -name '*.ogg' -print
      </pre>

      <p>
		  Suprimir paraules funciona igual que moure's per paraules,
		  però el caràcters que es trobe seràn suprimits. <a class="xref" href="#chap-shell-moving-word-shortcuts-delete" title="Table 7.5. Eliminar paraules">Table 7.5, “Eliminar paraules ”</a> llista les
		dreceres que s'empren per a suprimir paraules.
		  
	
      </p>

      <div class="table">
<a name="chap-shell-moving-word-shortcuts-delete"></a><p class="title"><b>Table 7.5. Eliminar paraules </b></p>
<div class="table-contents">
	
	<table summary="Eliminar paraules " border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Tecles</th>
<th>Descripció</th>
</tr></thead>
<tbody>
<tr>
<td>
		Alt-d
	      </td>
<td>
			  Suprimir la paraula, començant en la posició actual del 
			  cursor.
		
	      </td>
</tr>
<tr>
<td>
		Alt-Backspace
	      </td>
<td>
			  Eliminar cada caràcter desde la posició actual del cursor
			  fins al primer caràcter de la primera paraula què es trobe.
		
	      </td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
		  Per a acabar, hi ha algunes dreceres útils per a manipular
		  parauels. Estes dreceres es llisten a <a class="xref" href="#chap-shell-moving-word-shortcuts-modify" title="Table 7.6. Modificant paraules">Table 7.6, “Modificant paraules ”</a>.
	
      </p>

      <div class="table">
<a name="chap-shell-moving-word-shortcuts-modify"></a><p class="title"><b>Table 7.6. Modificant paraules </b></p>
<div class="table-contents">
	
	<table summary="Modificant paraules " border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Tecles</th>
<th>Descripció</th>
</tr></thead>
<tbody>
<tr>
<td>Alt-t</td>
<td>
			  Intercanvia (transposa) la paraula actual amb l'anterior.
		
	      </td>
</tr>
<tr>
<td>Alt-u</td>
<td>
			  Posar la paraula en majúscules, començant a la posició 
			  actual del cursor.
		
	      </td>
</tr>
<tr>
<td>Alt-l</td>
<td>
			  Posar la paraula en minúscules, començant a la posició 
			  actual del cursor.
		
	      </td>
</tr>
<tr>
<td>Alt-c</td>
<td>
			 Posa en majúscules la lletra actual de la paraula o la
			 pròxima lletra que trobe.
		
	      </td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
		  La transposició intercanvia paraules. Si s'utlitzen paraules
		  normals el seu comportament es pot predir. Per exemple, is 
		  tenim la següent línia amb el cursor a <span class="quote">“<span class="quote">two</span>”</span>
	
      </p>

      <pre class="screen">
un <span class="cursor">d</span>os tres
      </pre>

      <p>
		  La transposició de paraules intercanviarà <span class="quote">“<span class="quote">dos</span>”</span> 
		  and <span class="quote">“<span class="quote">un</span>”</span>:
	
      </p>

      <pre class="screen">
dos un tres
      </pre>

      <p>
		  Però si hi ha caràcters no alfabètics, el shell intercanviarà
		  la paraula amb l'anterior paraula preservant l'ordre dels 
		  caràcters no alfabètics. Açò és molt pràctic per a editar
		  arguments d'ordres. Suposa que has comés una errada, i has
		  mesclat la extensió del fitxer que vols buscar i el paràmetre
		  <span class="emphasis"><em>print</em></span>:
		  
	
      </p>

      <pre class="screen">
find ~/music -name '*.print' -ogg
      </pre>

      <p>
		  Pots arreglar-ho posant el cursor en la segon paraula 
		  equivocada, en este cas <span class="quote">“<span class="quote">ogg</span>”</span>, i transposar les 
		  dos paraues. Açò ens donarà el resulta que volem:
	
      </p>

      <pre class="screen">
find ~/music -name '*.ogg' -print
      </pre>

      <p>
		  Per a acabar, hi ha algunes dreceres que canvien la 
		  capitalització de paraules. La drecera Alt-u posa tots els 
		  caràcters en majúscules, començant per la posició actual del 
		  cursor, fins el final de la paraula. Així, si tenim el nom 
		  <span class="quote">“<span class="quote">alícia</span>”</span> en minúscules, al posar-lo en majúscules
		  amb el cursor a la <span class="quote">“<span class="quote">i</span>”</span> dóna <span class="quote">“<span class="quote">alICE</span>”</span>.
		  Alt-l té el mateix comportament, però canvia les lletres per
		  minúscules. Així, si utilitzar Alt-l a <span class="quote">“<span class="quote">alÍCIA</span>”</span>
		  amb el cursor a <span class="quote">“<span class="quote">Í</span>”</span> canviarà la cadena a 
		  <span class="quote">“<span class="quote">alícia</span>”</span>. Alt-c posará el caràcter on està el
		  cursor o el següent caràcter alfabètic que trobe a majúscules.
		  Per exemple, prement Alt-c amb el cursor sobre l'<span class="quote">“<span class="quote">a</span>”</span> 
		  a <span class="quote">“<span class="quote">alice</span>”</span> donarà lloc a <span class="quote">“<span class="quote">Alice</span>”</span>.
	
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-shell-moving-line"></a>7.3.3. Manipulació de línies</h3></div></div></div>
      

      <p>
		  El més alt nivell al què podem manipular és la línia mateixa.
		  <a class="xref" href="#chap-shell-moving-line-shortcuts-move" title="Table 7.7. Movent-se per línies">Table 7.7, “Movent-se per línies”</a> 
		  llista les dos dreceres de moviment.
	
      </p>

      <div class="table">
<a name="chap-shell-moving-line-shortcuts-move"></a><p class="title"><b>Table 7.7. Movent-se per línies</b></p>
<div class="table-contents">
	
	<table summary="Movent-se per línies" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Tecles</th>
<th>Descripció</th>
</tr></thead>
<tbody>
<tr>
<td>Ctrl-a</td>
<td>
			  Mou al començament de la línea actual.
		
	      </td>
</tr>
<tr>
<td>Ctrl-e</td>
<td>
			  Mou al final de la línea actual.
		
	      </td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
		  Suposem que el cursor és en algun lloc pel mig de la línia:
	
      </p>

      <pre class="screen">
find ~/music -name<span class="cursor"> </span>'*.ogg' -print
      </pre>

      <p>
		  Presionant Ctrl-e una vegada mourá el cursor al final de la
		  línia:
	
      </p>

      <pre class="screen">
find ~/music -name '*.ogg' -print<span class="cursor"> </span>
      </pre>

      <p>
		  Pressionant Ctrl-a mourà el cursor al començament de la línia:
	
      </p>

      <pre class="screen">
<span class="cursor">f</span>ind ~/music -name '*.ogg' -print
      </pre>

      <p>
		  Pots, a més, suprimir els caràcters a nivell de línia. Les
		  dreceres estàn llistades a: <a class="xref" href="#chap-shell-moving-line-shortcuts-delete" title="Table 7.8. Suprimint línies">Table 7.8, “Suprimint línies”</a>. Estes dreceres
		funcionen com el moviment, però elimina tots els caràcters que es
		troba. Ctrl-k suprimirà el caràcter on es troba el cursor, mentres 
		que	Ctrl-x Backspace no. Moure's al començament de la línia amb 
		Ctrl-a, seguit de Ctrl-k, és un truc ràpid per a suprimir una línia
		completament.
	
      </p>

      <div class="table">
<a name="chap-shell-moving-line-shortcuts-delete"></a><p class="title"><b>Table 7.8. Suprimint línies</b></p>
<div class="table-contents">
	
	<table summary="Suprimint línies" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Tecles</th>
<th>Descripció</th>
</tr></thead>
<tbody>
<tr>
<td>Ctrl-k</td>
<td>
			  Suprimeix tots els caràcters de la línia, començant a la
			  posició del cursor.
		
	      </td>
</tr>
<tr>
<td>Ctrl-x Backspace</td>
<td>
			 Elimina tots els caràcters de la línia fins al caràcter 
			 actual
		
	      </td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-shell-history"></a>7.4. Historial d'ordres </h2></div></div></div>
    

    <p>
		De vegades passa que has d'executar ordres que ja has executat
		abans. Afortunadament, no cal que les tecleges totes una altra
		vegada. Pots buscar a l'historial d'ordres executades amb les
		fletxes amunt i avall. A més d'això es pot buscar una ordre,
		prem Control-r i comença a teclejar la ordre que vols executar.
		Te n'adonaràs de que bash mostra la primera coincidència que 
		trobe, si esta no és la que busques, pots continuar escrivint
		la ordre (fins que només aparega una coincidència) o premer
		Control-r una vegada més per a obtindre la següent coincidència.
		Quan hages trobat la coincidència que buscàves, pots executar-la
		prement &lt;Enter&gt;.
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-shell-completion"></a>7.5. Autocompletat</h2></div></div></div>
    

    <p>
		L'autocompletat és una de les funcionalitats més útils dels 
		shell tipus UNIX. Suposa que tens un directori amb dos fitxers
		anomenats <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">websites</code></html:span> i      
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">recepta</code></html:span>. Suposa també que vols fer 
		<span class="command"><strong>cat</strong></span> del fitxer <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">websites</code></html:span>
		(<span class="command"><strong>cat</strong></span> mostra el contingut d'un fitxer), 
		especificant <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">websites</code></html:span> com a paràmetre de
		cat. En condicions normals, teclejaries 
		<span class="quote">“<span class="quote">cat websites</span>”</span> i executaries la ordre. Prova a
		teclejar <span class="quote">“<span class="quote">cat w</span>”</span>, i colpeja la tecla &lt;Tab&gt;.
		Bash ho expandirà automàticament a <span class="quote">“<span class="quote">cat websites</span>”</span>.
		
      
    </p>

    <p>
		Però què passa si tens vàris fitxers que començen amb la mateixa
		lletra? Suposa que tens els fitxers 
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">recepta1.txt</code></html:span> i
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">recepta2.txt</code></html:span>. Tecleja <span class="quote">“<span class="quote">cat r</span>”</span> 
		i dona-li a &lt;Tab&gt;, Bash completaria el fitxer fins on 
		puguera, el que et deixaria amb <span class="quote">“<span class="quote">cat recepta</span>”</span>. 
		Prova a pegar-li a &lt;Tab&gt; de nou i Bash mostrarà una llista
		de fitxers que començer amb <span class="quote">“<span class="quote">recepta</span>”</span>, en este cas
		els dos fitxers de recpetes. En este punt has d'ajudar al Bash
		esrivint el pròxim caràcter del fitxer que necessites. Suposa
		que vols fer <span class="command"><strong>cat</strong></span> de 
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">recepta2.txt</code></html:span>, pots premer la tecla 
		&lt;2&gt;. Després d'això no hi ha conflicter per a completar el 
		nom, i pegant-li a la tecla &lt;Tab&gt; es completa la ordre com
		<span class="quote">“<span class="quote">cat recipe2.txt</span>”</span>.
 		
      
    </p>

    <p>
		No cal dir que autocompletar funciona també amb órdres, però 
		moltes ordres GNU/Linux són curtes, pel que not resulta massa
		útil en este cas.
      
    </p>

    <p>
		És una bona idea practicar una miqueta amb l'autocompletat, et
		pot estalviar moltes pulsacions de tecla si t'hi manejes bé.
		Pots crear alguns fitxers buits per a practicar mitjançant la
		ordre <span class="command"><strong>touch</strong></span>. Per exemple, per a crear un 
		fitxer anomenat <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">recepta3.txt</code></html:span>, executa 
		<span class="command"><strong>touch recepta3.txt</strong></span>.
		
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-shell-wildcards"></a>7.6. Comodins </h2></div></div></div>
    

    <p>
		La majoria de shells, incloent Bash i ksh, suporten comodins.
		Els comodins són uns caràctera especials que es poden utilitzar
		per a fer coincidir patrons. La taula de més avall mostra
		alguns comodins freqüentment utilitzats. Anem a veurer vàris
		exemples per a donar una idea general de com funcionen els
		comodins.
      
    </p>

    <div class="table">
<a name="chap-shell-wildcards-thewildcards"></a><p class="title"><b>Table 7.9. Comodins Bash </b></p>
<div class="table-contents">
      

      <table summary="Comodins Bash " border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th align="left">Comodí</th>
<th align="left">Coincideix amb</th>
</tr></thead>
<tbody>
<tr>
<td align="left">*</td>
<td align="left">Una cadena de caràcters</td>
</tr>
<tr>
<td align="left">?</td>
<td align="left">Un únic caràcter </td>
</tr>
<tr>
<td align="left">[]</td>
<td align="left">Un únic caràcter en una matriu de caràcters 
	    </td>
</tr>
</tbody>
</table>
    </div>
</div>
<br class="table-break">

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-shell-wildcards-string"></a>7.6.1. Fent coincidir una cadena de caràcters</h3></div></div></div>
      

      <p>
		  Com es pot veurer en la taula de damunt, el caràcter 
		  <span class="quote">“<span class="quote">*</span>”</span> coincideix amb una cadena de caràcters. Per
		  exemple, <span class="emphasis"><em>*.html</em></span> coincideix amb totes les
		  cadenes de caràcters acabades en <span class="emphasis"><em>.html</em></span>,
		  <span class="emphasis"><em>d*.html</em></span> coincideix amb qualsevol cosa
		  que comence per <span class="emphasis"><em>d</em></span> i que acabe amb
		  <span class="emphasis"><em>.html</em></span>.
	
      </p>

      <p>
		  Suposem que vos agradaria llistar tots els fitxers del 
		  directori actual amb l'extensió <span class="emphasis"><em>.html</em></span>, la
		  órdre següent faria la feina:
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls *.html</code></strong>
book.html        installation.html     pkgmgmt.html  usermgmt.html
filesystem.html  internet.html         printer.html  xfree86.html
gfdl.html        introduction.html     proc.html
help.html        slackware-basics.html shell.html
      </pre>

      <p>
		  De la mateixa manera, podriem eliminar tots els fitxers que
		  comencen per <span class="emphasis"><em>in</em></span>:
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>rm in*</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-shell-wildcards-single"></a>7.6.2. Fent coincidir un caràcter </h3></div></div></div>
      

      <p>
		  El comodí <span class="quote">“<span class="quote">?</span>”</span> funciona com el <span class="quote">“<span class="quote">?</span>”</span>, 
		  però fa coincidir un únic caràcter. Suposem que tenim tres
		  fitxers <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">fitxer1.txt</code></html:span>,
		  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">fitxer2.txt</code></html:span> i
		  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">fitxer3.txt</code></html:span>. La cadena 
		  <span class="emphasis"><em>fitxer?.txt</em></span> coincideix amb els tres
		  fitxers, però no coincideix amb <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file10.txt</code></html:span>
		  (<span class="quote">“<span class="quote">10</span>”</span> són dos caràcters).
	
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-shell-wildcards-set"></a>7.6.3. Fent coincidir caràcters d'un conjunt </h3></div></div></div>
      

      <p>
		  El comodí <span class="quote">“<span class="quote">[]</span>”</span> concideix amb cada caràcter entre
		  claudàtors. Suposem que tenim els fitxers del exemple anterior
		  , <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">fitxer1.txt</code></html:span>,
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">fitxer2.txt</code></html:span> and
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">fitxer3.txt</code></html:span>. The string
	<span class="emphasis"><em>fitxer[23].txt</em></span> coincideix amb
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file2.txt</code></html:span> i
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file3.txt</code></html:span>, però no amb
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file1.txt</code></html:span>.
	
	
      </p>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-shell-inout"></a>7.7. Redireccions i canonades </h2></div></div></div>
    

    <p>
		Una de les principals característiques dels shells tipus UNIX
		són les redireccions i les canonades. Abans de començar amb
		veurer com funciones les dos tècniques em de mirar com treballen
		la majoria d'ordres tipus UNIX. Quan una ordre no rep data d'un 
		fitxer, obrirà un pseudo-fitxer anomenat 
		<span class="emphasis"><em>stdin</em></span> i quedarà esperant a que hi apareguen
		dades. El mateix principi es pot aplicar a la eixida d'una ordre
		, quan no hi ha una raó explícita per a alçar la eixida en un
		fitxer, el pseudo-fitxer <span class="emphasis"><em>stdout</em></span> serà obert
		per a enviarli-la. Este principi es mostra de manera esquemàtica
		a <a class="xref" href="#fig-shell-inout" title="Figure 7.1. Entrada i eixida estàndar">Figure 7.1, “Entrada i eixida estàndar ”</a>
      
    </p>

    <div class="figure">
<a name="fig-shell-inout"></a><p class="title"><b>Figure 7.1. Entrada i eixida estàndar </b></p>
<div class="figure-contents">
      
      <div class="mediaobject"><img src="../../images/shell-inout.png" alt="Entrada i eixida estàndar"></div>
    </div>
</div>
<br class="figure-break">

    <p>
	  Pots veurer <span class="emphasis"><em>stdin</em></span> i
	  <span class="emphasis"><em>stdout</em></span> en acció amb la ordre 
	  <span class="command"><strong>cat</strong></span>. Si cat s'inicia sense paràmetres aquest
	  senzillament es quedarà esperant dades a 
	  <span class="emphasis"><em>stdin</em></span> i les enviarà a 
	  <span class="emphasis"><em>stdout</em></span>. Si no s'utilitz cap redirecció,
	  s'utilitzarà la entrada de teclat per a <span class="emphasis"><em>stdin</em></span>
	  i la eixida de <span class="emphasis"><em>stdout</em></span> serà impresa al
	  terminal:
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>cat</code></strong>
<span class="command"><strong>Hello world!</strong></span>
Hello world!
    </pre>

    <p>
		Com pots veurer cat imprimirà les dades a <span class="emphasis"><em>stdout
		</em></span>	després d'introduirli-les a <span class="emphasis"><em>stdin
		</em></span>	utilitzant el teclat.
      
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-shell-inout-redir"></a>7.7.1. Redirecció </h3></div></div></div>
      

      <p>
		  El shell et permet prendre utilització de 
		  <span class="emphasis"><em>stdin</em></span> i <span class="emphasis"><em>stdout</em></span>
		  utilitzant <span class="quote">“<span class="quote">&lt;</span>”</span> i <span class="quote">“<span class="quote">&gt;</span>”</span>. En el 
		  següent exemple redireccionarem els resums md5 calculats per
		  a un conjunt de fitxers a un fitxer anomenat 
		  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">md5sums</code></html:span>:
		  
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>md5sum * &gt; md5sums</code></strong>
$ <strong class="userinput"><code>cat md5sums</code></strong> 
6be249ef5cacb10014740f61793734a8  test1
220d2cc4d5d5fed2aa52f0f48da38ebe  test2
631172a1cfca3c7cf9e8d0a16e6e8cfe  test3
      </pre>

      <p>
	Com poden veurer en la eixida de <span class="command"><strong>cat</strong></span> la eixida
	de <span class="command"><strong>md5sum *</strong></span> ha sigut redirigida al fitxer
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">md5sums</code></html:span>. Nosaltres a més podem utilitzar la
	redirecció per a proporcionar-li l'entrada a una ordre:
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>md5sum &lt; test1</code></strong>
6be249ef5cacb10014740f61793734a8  -
      </pre>

      <p>
	Açò alimenta a <span class="command"><strong>md5sum</strong></span> amb el contingut del fitxer
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">test1</code></html:span>.
	
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-shell-inout-pipes"></a>7.7.2. Canonades </h3></div></div></div>
      

      <p>
	També pots conectar la entrad i la eixida d'ordres utilitzant
	les anomenades <span class="emphasis"><em>canonades (pipes)</em></span>. Una
	canonada entre ordres es pot construir amb el caràcter 
	<span class="quote">“<span class="quote">|</span>”</span>. Dos o més ordres combinades es diu que 
	formen una <span class="quote">“<span class="quote">conducció (pipiline)</span>”</span>. <a class="xref" href="#fig-shell-pipeline" title="Figure 7.2. Una conducció">Figure 7.2, “Una conducció ”</a> mostra un resum esquemàtic d'una 
	conducció consistent en dos ordres.
	
	
      </p>

      <div class="figure">
<a name="fig-shell-pipeline"></a><p class="title"><b>Figure 7.2. Una conducció </b></p>
<div class="figure-contents">
	
	<div class="mediaobject"><img src="../../images/shell-pipeline.png" alt="Una conducció"></div>
      </div>
</div>
<br class="figure-break">

      <p>
		  La sintaxi de una conducció és <span class="command"><strong>ordre1 | ordre2 ... 
		  | ordren</strong></span>. Si conéixes com funcionen la majoria 
		  d'ordres bàsiques tipus UNIX, ja pots deixar que aquestes
		  treballen juntes. Vejam un exemple ràpid:
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat /usr/share/dict/american-english | grep "aba" | wc -l</code></strong>
123
      </pre>

      <p>
	La primera ordre, <span class="command"><strong>cat</strong></span>, llig el fitxer de 
	diccionari <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/share/dict/american-english</code></html:span>. La
	eixida de la ordre <span class="command"><strong>cat</strong></span> es canalitza a la ordre
	<span class="command"><strong>grep</strong></span>, que imprimeix els fitxers que contenen la 
	paraula <span class="quote">“<span class="quote">aba</span>”</span>. A continuació, la eixida de 
	<span class="quote">“<span class="quote">grep</span>”</span> es canalitza cap a <span class="command"><strong>wc -l</strong></span>,
	que comptabilitza el nombre de línies que rep de 
	<span class="emphasis"><em>stdin</em></span>. Per acabar, quan el fluxe s'ha acabat
	<span class="command"><strong>wc</strong></span> imprimeix el nombre de línies que contenen la
	paraula <span class="quote">“<span class="quote">aba</span>”</span> en este diccionari en particular.
	
	
      </p>

      <p>
	Hi ha centenars de xicotetes utilitats per a manejar tasques
	específiques. Com et podràs imaginar, aquestes ordres juntes
	proporciones una caixa d'eines molt potent fent-hi combinacions
	mitjançant canonades.
	
	
      </p>
    </div>
  </div>
</div>
    <div lang="en" class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-filesystem"></a>Chapter 8. Files and directories</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-filesystem-introduction">8.1. Some theory</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystems-analyzing">8.2. Analyzing files</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-directories">8.3. Working with directories</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-managing">8.4. Managing files and directories</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-permissions">8.5. Permissions</a></span></dt>
<dt><span class="sect1"><a href="#chap-filesystem-finding">8.6. Finding files</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-archives">8.7. Archives</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-mounting">8.8. Mounting filesystems</a></span></dt>
<dt><span class="sect1"><a href="#basics-filesystem-gnupg">8.9. Encrypting and signing files</a></span></dt>
</dl>
</div>
  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-filesystem-introduction"></a>8.1. Some theory</h2></div></div></div>
    

    <p>
      Before we move on to look at practical filesystem operations, we
      are going to look at a more theoretical overview of how
      filesystems on UNIX-like systems work. Slackware Linux supports
      many different filesystems, but all these filesystems use
      virtually the same semantics. These semantics are provided
      through the <span class="emphasis"><em>Virtual Filesystem</em></span> (VFS)
      layer, giving a generic layer for disk and network filesystems.
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-introduction-atoms"></a>8.1.1. inodes, directories and data</h3></div></div></div>
      

      <p>
	The filesystem consists of two types of elements: data and
	metadata. The metadata describes the actual data blocks that
	are on the disk. Most filesystems use information nodes
	(inodes) to store metadata. Most filesystems store the
	following data in their inodes:
      </p>

      <div class="table">
<a name="chap-filesystem-introduction-atoms-inodes"></a><p class="title"><b>Table 8.1. Common inode fields</b></p>
<div class="table-contents">
        
        <table summary="Common inode fields" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Field</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td>mode</td>
<td>The file permissions.</td>
</tr>
<tr>
<td>uid</td>
<td>The user ID of the owner of the file.</td>
</tr>
<tr>
<td>gid</td>
<td>The group ID of the group of the file.</td>
</tr>
<tr>
<td>size</td>
<td>Size of the file in bytes.</td>
</tr>
<tr>
<td>ctime</td>
<td>File creation time.</td>
</tr>
<tr>
<td>mtime</td>
<td>Time of the last file modification.</td>
</tr>
<tr>
<td>links_count</td>
<td>The number of links pointing to this inode.</td>
</tr>
<tr>
<td>i_block</td>
<td>Pointers to data blocks</td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
	If you are not a UNIX or Linux afficiendo, these names will
	probably sound bogus to you, but we will clear them up in the
	following sections. At any rate, you can probably deduct the
	relation between inodes and data from this table, and
	specifically the <span class="emphasis"><em>i_block</em></span> field: every
	inode has pointers to the data blocks that the inode provides
	information for. Together, the inode and data blocks are the
	actual file on the filesystem.
      </p>

      <p>
	You may wonder by now where the names of files (and
	directories) reside, since there is no file name field in the
	inode. Actually, the names of the files are separated from the
	inode and data blocks, which allows you to do groovy stuff,
	like giving the same file more than one name. The filenames
	are stored in so-called directory entries. These entries
	specify a filename and the inode of the file. Since
	directories are also represented by inodes, a directory
	structure can also be constructed in this manner.
      </p>

      <p>
	We can simply show how this all works by illustrating what the
	kernel does when we execute the command <span class="command"><strong>cat
	/home/daniel/note.txt</strong></span>
      </p>

      <div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
	  <p>
	    The system reads the inode of the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span>
	    directory, checks if the user is allowed to access this
	    inode, and reads the data block to find the inode number
	    of the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">home</code></html:span> directory.
	  </p>
        </li>
<li class="listitem">
          <p>
	    The system reads the inode of the
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">home</code></html:span> directory, checks if the user is
	    allowed to access this inode, and reads the data block to
	    find the inode number of the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">daniel</code></html:span>
	    directory. </p>
        </li>
<li class="listitem">
          <p>
	    The system reads the inode of the
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">daniel</code></html:span> directory, checks if the user is
	    allowed to access this inode, and reads the data block to
	    find the inode number of the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">note.txt</code></html:span>
	    file.
	  </p>
        </li>
<li class="listitem">
          <p>
	    The system reads the inode of the
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">note.txt</code></html:span> file, checks if the user
	    is allowed to access this inode, and returns the data
	    blocks to <span class="command"><strong>cat</strong></span> through the
	    <span class="emphasis"><em>read()</em></span> system call. </p>
        </li>
</ol></div>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-introduction-permissions"></a>8.1.2. File permissions</h3></div></div></div>
      

      <p>
	As we have described earlier, Linux is a multi-user
	system. This means that each user has his/her own files (that
	are usually located in the home directory). Besides that users
	can be members of a group, which may give the user additional
	privileges.
      </p>

      <p>
	As you have seen in the inode field table, every file has a
	owner and a group.  Traditional UNIX access control gives
	read, write, or executable permissions to the file owner, file
	group, and other users. These permissions are stored in the
	<span class="emphasis"><em>mode</em></span> field of the inode. The mode field
	represents the file permissions as a four digit octal
	number. The first digit represents some special
	options, the second digit stores the owner permissions, the
	third the group permissions, and the fourth the permissions
	for other users. The permissions are established by digit by
	using or adding one of the number in <a class="xref" href="#chap-filesystem-permissions-numbers" title="Table 8.2. Meaning of numbers in the mode octet">Table 8.2, “Meaning of numbers in the mode octet”</a>
      </p>

      <div class="table">
<a name="chap-filesystem-permissions-numbers"></a><p class="title"><b>Table 8.2. Meaning of numbers in the mode octet</b></p>
<div class="table-contents">
        
        <table summary="Meaning of numbers in the mode octet" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Number</th>
<th>Meaning</th>
</tr></thead>
<tbody>
<tr>
<td>1</td>
<td>Execute (x)</td>
</tr>
<tr>
<td>2</td>
<td>Write (w)</td>
</tr>
<tr>
<td>4</td>
<td>Read (r)</td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
	Now, suppose that a file has mode <span class="emphasis"><em>0644</em></span>,
	this means that the file is readable and writable by the owner
	(<span class="emphasis"><em>6</em></span>), and readable by the file group
	(<span class="emphasis"><em>4</em></span>) and others
	(<span class="emphasis"><em>4</em></span>). </p>

      <p>
	Most users do not want to deal with octal numbers, so that is
	why many utilities can also deal with an alphabetic
	representation of file permissions. The letters that are
	listed in <a class="xref" href="#chap-filesystem-permissions-numbers" title="Table 8.2. Meaning of numbers in the mode octet">Table 8.2, “Meaning of numbers in the mode octet”</a> between
	parentheses are used in this notation. In the following
	example information about a file with
	<span class="emphasis"><em>0644</em></span> permissions is printed. The numbers
	are replaced by three rwx triplets (the first character can
	list special mode options).
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls -l note.txt</code></strong>
-rw-r--r--  1 daniel daniel 5 Aug 28 19:39 note.txt
      </pre>

      <p>
	Over the years these traditional UNIX permissions have proven
	not to be sufficient in some cases. The POSIX 1003.1e
	specification aimed to extend the UNIX access control model
        with <span class="emphasis"><em>Access Control Lists</em></span> (ACLs).
	Unfortunately this effort stalled,
        though some systems (like GNU/Linux) have implemented ACLs<a href="#ftn.idm951380196" class="footnote" name="idm951380196"><sup class="footnote">[4]</sup></a>. Access control
        lists follow the same semantics as normal file permissions,
        but give you the opportunity to add <span class="emphasis"><em>rwx</em></span>
        triplets for additional users and groups. </p>

      <p>
	The following example shows the access control list of a
	file. As you can see, the permissions look like normal UNIX
	permissions (the access rights for the user, group, and others
	are specified). But there is also an additional entry for the
	user <span class="emphasis"><em>joe</em></span>.
      </p>

      <pre class="programlisting">
user::rwx
user:joe:r--
group::---
mask::r--
other::---
      </pre>

      <p>
	To make matters even more complex (and sophisticated), some
	GNU/Linux systems add more fine-grained access control through
	Mandatory Access Control Frameworks (MAC) like SELinux and
	AppArmor. But these access control frameworks are beyond the
	scope of this book.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystems-introduction-links"></a>8.1.3. Links</h3></div></div></div>
      

      <p>
	A directory entry that points to an inode is named a
	<span class="emphasis"><em>hard link</em></span>.  Most files are only linked
	once, but nothing holds you from linking a file twice. This
	will increase the <span class="emphasis"><em>links_count</em></span> field of
	the inode. This is a nice way for the system to see which
	inodes and data blocks are free to use. If links_count is set
	to zero, the inode is not referred to anymore, and can be
	reclaimed.
      </p>

      <div class="figure">
<a name="chap-filesystems-introduction-links-hardlink"></a><p class="title"><b>Figure 8.1. The structure of a hard link</b></p>
<div class="figure-contents">
        

        <div class="mediaobject"><img src="../../images/hardlink.png" alt="The structure of a hard link"></div>
      </div>
</div>
<br class="figure-break">

      <p>
	Hard links have two limitations. First of all, hard links can
	not interlink between file systems, since they point to
	inodes. Every filesystem has its own inodes and corresponding
	inode numbers. Besides that, most filesystems do not allow you
	to create hard links to directories. Allowing creation of hard
	links to directories could produce directory loops,
	potentially leading to deadlocks and filesystem
	inconsistencies. In addition to that, most implementations of
	<span class="command"><strong>rm</strong></span> and <span class="command"><strong>rmdir</strong></span> do not know
	how to deal with such extra directory hard links.
      </p>

      <p>
        <span class="emphasis"><em>Symbolic links</em></span> do not have these
        limitations, because they point to file names, rather than
        inodes. When the symbolic link is used, the operating system
        will follow the path to that link. Symbolic links can also
        refer to a file that does not exist, since it just contains a
        name. Such links are called dangling links.
      </p>

      <div class="figure">
<a name="chap-filesystems-introduction-links-symlink"></a><p class="title"><b>Figure 8.2. The structure of a symbolic link</b></p>
<div class="figure-contents">
        

        <div class="mediaobject"><img src="../../images/symlink.png" alt="The structure of a symbolic link"></div>
      </div>
</div>
<br class="figure-break">

      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
        <p>
	  If you ever get into system administration, it is good to be
	  aware of the security implications of hard links. If the
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home</code></html:span> directory is on the same
	  filesystem as any system binaries, a user will be able to
	  create hard links to binaries.  In the case that a
	  vulnerable program is upgraded, the link in the user's home
	  directory will keep pointing to the old program binary,
	  effectively giving the user continuing access to a
	  vulnerable binary.
	</p>

        <p>
	  For this reason it is a good idea to put any directories
	  that users can write to on different filesystems. In
	  practice, this means that it is a good idea to put at least
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home</code></html:span> and <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/tmp</code></html:span> on
	  separate filesystems.
        </p>
      </td></tr>
</table></div>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-filesystems-analyzing"></a>8.2. Analyzing files</h2></div></div></div>
    

    <p>
      Before going to some more adventurous venues, we will start
      with some file and directory usage basics.
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystems-analyzing-listing"></a>8.2.1. Listing files</h3></div></div></div>
      

      <p>
	One of the most common things that you will want to do is to
	list all or certain files. The <span class="command"><strong>ls</strong></span> command
	serves this purpose very well. Using <span class="command"><strong>ls</strong></span>
	without any arguments will show the contents of the actual
	directory:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls</code></strong>
dns.txt  network-hosts.txt  papers
      </pre>

      <p>
	If you use a GNU/Linux distribution, you may also see some
	fancy coloring based on the type of file. The standard output
	is handy to skim through the contents of a directory, but if
	you want more information, you can use the <em class="parameter"><code>-l</code></em> parameter. This provides a
	so-called long listing for each file:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls -l</code></strong>
total 36
-rw-rw-r--  1 daniel daniel 12235 Sep  4 15:56 dns.txt
-rw-rw-r--  1 daniel daniel  7295 Sep  4 15:56 network-hosts.txt
drwxrwxr-x  2 daniel daniel  4096 Sep  4 15:55 papers
      </pre>

      <p>
	This gives a lot more information about the three directory
	entries that we have found with <span class="command"><strong>ls</strong></span>.  The
	first column shows the file permissions. The line that shows
	the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">papers</code></html:span> entry starts with a
	<span class="quote">“<span class="quote">d</span>”</span>, meaning that this entry represents a
	directory. The second column shows the number of hard links
	pointing to the inode that a directory entry points to. If
	this is higher than 1, there is some other filename for the
	same file. Directory entries usually have at least two hard
	links, namely the link in the parent directory and the link in
	the directory itself (each directory has a
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.</code></html:span> entry, which refers to the directory
	itself). The third and the fourth columns list the file owner
	and group respectively. The fifth column contains the file
	size in bytes. The sixth column the last modification time and
	date of the file. And finally, the last column shows the name
	of this entry.
      </p>

      <p>
	Files that start with a period (.) will not be shown by most
	applications, including <span class="command"><strong>ls</strong></span>. You can list
	these files too, by adding the <em class="parameter"><code>-a</code></em> option to
	<span class="command"><strong>ls</strong></span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls -la</code></strong>
total 60
drwxrwxr-x   3 daniel daniel  4096 Sep 11 10:01 .
drwx------  88 daniel daniel  4096 Sep 11 10:01 ..
-rw-rw-r--   1 daniel daniel 12235 Sep  4 15:56 dns.txt
-rw-rw-r--   1 daniel daniel  7295 Sep  4 15:56 network-hosts.txt
drwxrwxr-x   2 daniel daniel  4096 Sep  4 15:55 papers
-rw-rw-r--   1 daniel daniel     5 Sep 11 10:01 .settings
      </pre>

      <p>
	As you can see, three more entries have appeared. First of
	all, the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.settings</code></html:span> file is now
	shown. Besides that you can see two additional directory
	entries, <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.</code></html:span> and
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">..</code></html:span>. These represent the current directory
	and the parent directory respectively.
      </p>

      <p>
	Earlier in this chapter (<a class="xref" href="#chap-filesystem-introduction-atoms" title="8.1.1. inodes, directories and data">Section 8.1.1, “inodes, directories and data”</a>) we talked
	about inodes. The inode number that a directory entry points
	to can be shown with the <em class="parameter"><code>-i</code></em> parameter. Suppose that I have
	created a hard link to the inode that points to the same inode
	as <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">dns.txt</code></html:span>, they should have the same
	inode number. The following <span class="command"><strong>ls</strong></span> output shows
	that this is true:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls -i dns*</code></strong>
3162388 dns-newhardlink.txt
3162388 dns.txt
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-analyzing-file"></a>8.2.2. Determining the type of a file</h3></div></div></div>
      

      <p>
	Sometimes you will need some help to determine the type of a
	file. This is where the <span class="command"><strong>file</strong></span> utility
	becomes handy. Suppose that I find a file named
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">HelloWorld.class</code></html:span> somewhere on my disk. I
	suppose that this is a file that holds Java bytecode, but we
	can use <span class="command"><strong>file</strong></span> to check this:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>file HelloWorld.class</code></strong>
HelloWorld.class: compiled Java class data, version 49.0
      </pre>

      <p>
	That is definitely Java bytecode. <span class="command"><strong>file</strong></span> is
	quite smart, and handles most things you throw at it. For
	instance, you could ask it to provide information about a
	device node:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>file /dev/zero</code></strong>
/dev/zero: character special (1/5)
      </pre>

      <p>
	Or a symbolic link:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>file /usr/X11R6/bin/X</code></strong>
/usr/X11R6/bin/X: symbolic link to `Xorg'
      </pre>

      <p>
	If you are rather interested in the file
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/X11R6/bin/X</code></html:span> links to, you can use
	the <em class="parameter"><code>-L</code></em> option of
	<span class="command"><strong>file</strong></span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>file -L /usr/X11R6/bin/X</code></strong>
/usr/X11R6/bin/X: setuid writable, executable, regular file, no read permission
      </pre>

      <p>
	You may wonder why <span class="command"><strong>file</strong></span> can determine the
	file type relatively easy. Most files start of with a
	so-called <span class="emphasis"><em>magic number</em></span>, this is a unique
	number that tells programs that can read the file what kind of
	file it is. The <span class="command"><strong>file</strong></span> program uses a file
	which describes many file types and their magic numbers.  For
	instance, the magic file on my system contains the following
	lines for Java compiled class files:
      </p>

      <pre class="programlisting">
# Java ByteCode
# From Larry Schwimmer (schwim@cs.stanford.edu)
0       belong          0xcafebabe      compiled Java class data,
&gt;6      beshort x       version %d.
&gt;4      beshort x       \b%d
      </pre>

      <p>
	This entry says that if a file starts with a long (32-bit)
	hexadecimal magic number <span class="emphasis"><em>0xcafebabe</em></span><a href="#ftn.idm951348060" class="footnote" name="idm951348060"><sup class="footnote">[5]</sup></a>, it is a file that holds
          <span class="quote">“<span class="quote">compiled Java class data</span>”</span>. The short that
          follows determines the class file format version.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-analyzing-integrity"></a>8.2.3. File integrity</h3></div></div></div>
      

      <p>
	While we will look at more advanced file integrity checking
	later,  we will have a short look at the
	<span class="command"><strong>cksum</strong></span> utility. <span class="command"><strong>cksum</strong></span> can
	calculate a cyclic redundancy check (CRC) for an input
	file. This is a mathematically sound method for calculating a
	unique number for a file. You can use this number to check
	whether a file is unchanged (for example, after downloading a
	file from a server). You can specify the file to calculate a
	CRC for as a parameter to <span class="command"><strong>cksum</strong></span>, and
	<span class="command"><strong>cksum</strong></span> will print the CRC, the file size in
	bytes, and the file name:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cksum myfile</code></strong>
1817811752 22638 myfile
      </pre>

      <p>
	Slackware Linux also provides utilities for calculating
	checksums based on one-way hashes (for instance MD5 or SHA-1).
	
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-analyzing-viewing"></a>8.2.4. Viewing files</h3></div></div></div>
      

      <p>
	Since most files on UNIX systems are usually text files, they
	are easy to view from a character-based terminal or terminal
	emulator. The most primitive way of looking at the contents of
	a file is by using <span class="command"><strong>cat</strong></span>.
	<span class="command"><strong>cat</strong></span> reads files that were specified as a
	parameter line by line, and will write the lines to the
	standard output. So, you can write the contents of the file
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">note.txt</code></html:span> to the terminal with
	<span class="command"><strong>cat note.txt</strong></span>. While some systems and most
	terminal emulators provide support for scrolling, this is not
	a practical way to view large files. You can pipe the output
	of <span class="command"><strong>cat</strong></span> to the <span class="command"><strong>less</strong></span>
	paginator:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat note.txt | less</code></strong>
      </pre>

      <p>
	or let <span class="command"><strong>less</strong></span> read the file directly:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>less note.txt</code></strong>
      </pre>

      <p>
	The <span class="command"><strong>less</strong></span> paginator lets you scroll forward
	and backward through a file. <a class="xref" href="#chap-filesystem-analyzing-viewing-less-keys" title="Table 8.3. less command keys">Table 8.3, “less command keys”</a>
	provides an overview of the most important keys that are used
	to control <span class="command"><strong>less</strong></span>
      </p>

      <div class="table">
<a name="chap-filesystem-analyzing-viewing-less-keys"></a><p class="title"><b>Table 8.3. less command keys</b></p>
<div class="table-contents">
        

        <table summary="less command keys" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Key</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td>j</td>
<td>Scroll forward one line.</td>
</tr>
<tr>
<td>k</td>
<td>Scroll backwards one line.</td>
</tr>
<tr>
<td>f</td>
<td>Scroll forward one screen full of text.</td>
</tr>
<tr>
<td>b</td>
<td>Scroll backwards one screen full of text.</td>
</tr>
<tr>
<td>q</td>
<td>Quit less.</td>
</tr>
<tr>
<td>g</td>
<td>Jump to the beginning of the file.</td>
</tr>
<tr>
<td>G</td>
<td>Jump to the end of the file.</td>
</tr>
<tr>
<td>/<span class="emphasis"><em>pattern</em></span>
</td>
<td> Search for the <a class="ulink" href="#chap-textproc-regexps" target="_top">regular expression</a>
                <span class="emphasis"><em>pattern</em></span>. </td>
</tr>
<tr>
<td>n</td>
<td> Search for the next match of the previously specified regular expression.
              </td>
</tr>
<tr>
<td>m<span class="emphasis"><em>letter</em></span>
</td>
<td> Mark the current position in the file with <span class="emphasis"><em>letter</em></span>.
              </td>
</tr>
<tr>
<td>'<span class="emphasis"><em>letter</em></span>
</td>
<td>Jump to the mark <span class="emphasis"><em>letter</em></span>
</td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
	The command keys that can be quantized can be prefixed by a
	number. For instance <span class="emphasis"><em>11j</em></span> scrolls forward
	eleven lines, and <span class="emphasis"><em>3n</em></span> searches the third
	match of the previously specified regular expression.
      </p>

      <p>
	Slackware Linux also provides an alternative to
	<span class="command"><strong>less</strong></span>, the older <span class="quote">“<span class="quote">more</span>”</span> command.
	We will not go into <span class="emphasis"><em>more</em></span> here,
	<span class="command"><strong>less</strong></span> is more comfortable, and also more popular
	these days.
      </p>

    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-analyzing-filesize"></a>8.2.5. File and directory sizes</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>ls -l</strong></span> output that we have seen earlier
	provides information about the size of a file. While this
	usually provides enough information about the size of files,
	you might want to gather information about collections of
	files or directories. This is where the <span class="command"><strong>du</strong></span>
	command comes in. By default, <span class="command"><strong>du</strong></span> prints the
	file size per directory. For example:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>du ~/qconcord</code></strong>
72      /home/daniel/qconcord/src
24      /home/daniel/qconcord/ui
132     /home/daniel/qconcord
      </pre>

      <p>
        By default, <span class="command"><strong>du</strong></span> represents the size in 1024
        byte units. You can explicitly specify that
        <span class="command"><strong>du</strong></span> should use 1024 byte units by adding the
        <em class="parameter"><code>-k</code></em> flag. This is useful
	for writing scripts, because some other systems default to
	using 512-byte blocks. For example:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>du -k ~/qconcord</code></strong>
72	/home/daniel/qconcord/src
24	/home/daniel/qconcord/ui
132	/home/daniel/qconcord
      </pre>

      <p>
	If you would also like to see per-file disk usage, you can add
	the <em class="parameter"><code>-a</code></em> flag:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>du -k -a ~/qconcord</code></strong>
8       /home/daniel/qconcord/ChangeLog
8       /home/daniel/qconcord/src/concordanceform.h
8       /home/daniel/qconcord/src/textfile.cpp
12      /home/daniel/qconcord/src/concordancemainwindow.cpp
12      /home/daniel/qconcord/src/concordanceform.cpp
8       /home/daniel/qconcord/src/concordancemainwindow.h
8       /home/daniel/qconcord/src/main.cpp
8       /home/daniel/qconcord/src/textfile.h
72      /home/daniel/qconcord/src
12      /home/daniel/qconcord/Makefile
16      /home/daniel/qconcord/ui/concordanceformbase.ui
24      /home/daniel/qconcord/ui
8       /home/daniel/qconcord/qconcord.pro
132     /home/daniel/qconcord
      </pre>

      <p>
	You can also use the name of a file or a wildcard as a
	parameter. But this will not print the sizes of files in
	subdirectories, unless <em class="parameter"><code>-a</code></em> is used:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>du -k -a ~/qconcord/*</code></strong>
8       /home/daniel/qconcord/ChangeLog
12      /home/daniel/qconcord/Makefile
8       /home/daniel/qconcord/qconcord.pro
8       /home/daniel/qconcord/src/concordanceform.h
8       /home/daniel/qconcord/src/textfile.cpp
12      /home/daniel/qconcord/src/concordancemainwindow.cpp
12      /home/daniel/qconcord/src/concordanceform.cpp
8       /home/daniel/qconcord/src/concordancemainwindow.h
8       /home/daniel/qconcord/src/main.cpp
8       /home/daniel/qconcord/src/textfile.h
72      /home/daniel/qconcord/src
16      /home/daniel/qconcord/ui/concordanceformbase.ui
24      /home/daniel/qconcord/ui
      </pre>

      <p>
	If you want to see the total sum of the disk usage of the
	files and subdirectories that a directory holds, use the
	<em class="parameter"><code>-s</code></em> flag:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>du -k -s ~/qconcord</code></strong>
132     /home/daniel/qconcord
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-filesystem-directories"></a>8.3. Working with directories</h2></div></div></div>
    

    <p>
      After having a bird's eye view of directories in <a class="xref" href="#chap-filesystem-introduction-atoms" title="8.1.1. inodes, directories and data">Section 8.1.1, “inodes, directories and data”</a>, we will have a
      look at some directory-related commands.
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-directories-listing"></a>8.3.1. Listing directories</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>ls</strong></span> command that we have looked at in
	<a class="xref" href="#chap-filesystems-analyzing-listing" title="8.2.1. Listing files">Section 8.2.1, “Listing files”</a> can also
	be used to list directories in various ways. As we have seen,
	the default <span class="command"><strong>ls</strong></span> output includes directories,
	and directories can be identified using the first output
	column of a long listing:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls -l</code></strong>
total 36
-rw-rw-r--  1 daniel daniel 12235 Sep  4 15:56 dns.txt
-rw-rw-r--  1 daniel daniel  7295 Sep  4 15:56 network-hosts.txt
drwxrwxr-x  2 daniel daniel  4096 Sep  4 15:55 papers
      </pre>

      <p>
	If a directory name, or if wildcards are specified,
	<span class="command"><strong>ls</strong></span> will list the contents of the directory,
	or the directories that match the wildcard respectively. For example,
	if there is a directory <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">papers</code></html:span>, <span class="command"><strong>ls
	paper*</strong></span> will list the contents of this directory
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">paper</code></html:span>. This is often annoying if you
	would just like to see the matches, and not the contents of
	the matching directories. The <em class="parameter"><code>-d</code></em> avoid that this recursion
	happens:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls -ld paper*</code></strong>
drwxrwxr-x  2 daniel daniel  4096 Sep  4 15:55 papers
      </pre>

      <p>
	You can also recursively list the contents of a directory, and
	its subdirectories with the <em class="parameter"><code>-R</code></em> parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls -R</code></strong>
.:
dns.txt  network-hosts.txt  papers

./papers:
cs  phil

./papers/cs:
entr.pdf

./papers/phil:
logics.pdf
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-directories-management"></a>8.3.2. Creating and removing directories</h3></div></div></div>
      

      <p>
	UNIX provides the <span class="command"><strong>mkdir</strong></span> command to create
	directories. If a relative path is specified, the directory is
	created in the current active directory. The basic syntax is
	very simple: <span class="emphasis"><em>mkdir &lt;name&gt;</em></span>, for
	example:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>mkdir mydir</code></strong>
      </pre>

      <p>
	By default, <span class="command"><strong>mkdir</strong></span> only creates one
	directory level. So, if you use <span class="command"><strong>mkdir</strong></span> to
	create <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">mydir/mysubdir</code></html:span>,
	<span class="command"><strong>mkdir</strong></span> will fail if
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">mydir</code></html:span> does not exist already. If you
	would like to create both directories at once, use the
	<em class="parameter"><code>-p</code></em> parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>mkdir -p mydir/mysubdir</code></strong>
      </pre>

      <p>
	<span class="command"><strong>rmdir</strong></span> removes a directory. Its behavior is
	comparable to <span class="command"><strong>mkdir</strong></span>. <span class="command"><strong>rmdir
	mydir/mysubdir</strong></span> removes <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">mydir/subdir</code></html:span>,
	while <span class="command"><strong>rmdir -p mydir/mysubdir</strong></span> removes
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">mydir/mysubdir</code></html:span> and then
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">mydir</code></html:span>.
      </p>

      <p>
	If a subdirectory that we want to remove contains directory
	entries, <span class="command"><strong>rmdir</strong></span> will fail. If you would like
	to remove a directory, including all its contents, use the
	<span class="command"><strong>rm</strong></span> command instead. 
      </p>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-filesystem-managing"></a>8.4. Managing files and directories</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-managing-copying"></a>8.4.1. Copying</h3></div></div></div>
      

      <p>
	Files and directories can be copied with the
	<span class="command"><strong>cp</strong></span> command. In its most basic syntax the
	source and the target file are specified. The following
	example will make a copy of <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file1</code></html:span> named
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file2</code></html:span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cp file1 file2</code></strong>
      </pre>

      <p>
	It is not surprising that relative and absolute paths do also
	work:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cp file1 somedir/file2</code></strong>
$ <strong class="userinput"><code>cp file1 /home/joe/design_documents/file2</code></strong>
      </pre>

      <p>
	You can also specify a directory as the second parameter. If
	this is the case, <span class="command"><strong>cp</strong></span> will make a copy of
	the file in that directory, giving it the same file name as
	the original file. If there is more than one parameter, the
	last parameter will be used as the target directory. For
	instance
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cp file1 file2 somedir</code></strong>
      </pre>

      <p>
	will copy both <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file1</code></html:span> and
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file2</code></html:span> to the directory
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">somedir</code></html:span>. You can not copy multiple files
	to one file. You will have to use <span class="command"><strong>cat</strong></span>
	instead: 
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat file1 file2 &gt; combined_file</code></strong>
      </pre>

      <p>
	You can also use <span class="command"><strong>cp</strong></span> to copy directories, by
	adding the <em class="parameter"><code>-R</code></em>. This
	will recursively copy a directory and all its
	subdirectories. If the target directory exists, the source
	directory or directories will be placed under the target
	directory. If the target directory does not exist, it will be
	created if there is only one source directory.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cp -r mytree tree_copy</code></strong>
$ <strong class="userinput"><code>mkdir trees</code></strong>
$ <strong class="userinput"><code>cp -r mytree trees</code></strong>
      </pre>

      <p>
	After executing these commands, there are two copies of the directory
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">mytree</code></html:span>, <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">tree_copy</code></html:span> and
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">trees/mytree</code></html:span>. Trying to copy two directories to a nonexistent target
        directory will fail:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cp -R mytree mytree2 newdir</code></strong>
usage: cp [-R [-H | -L | -P]] [-f | -i] [-pv] src target
       cp [-R [-H | -L | -P]] [-f | -i] [-pv] src1 ... srcN directory
      </pre>

      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
	<p>
	  Traditionally, the <em class="parameter"><code>-r</code></em>
	  has been available on many UNIX systems to recursively copy
	  directories. However, the behavior of this parameter can be
	  implementation-dependent, and the Single UNIX Specification
	  version 3 states that it may be removed in future versions
	  of the standard.
	</p>
      </td></tr>
</table></div>

      <p>
	When you are copying files recursively, it is a good idea to
	specify the behavior of what <span class="command"><strong>cp</strong></span> should do
	when a symbolic link is encountered explicitly, if you want
	to use <span class="command"><strong>cp</strong></span> in portable scripts. The
	Single UNIX Specification version 3 does not specify how they
	should be handled by default. If <em class="parameter"><code>-P</code></em> is used, symbolic links will
	not be followed, effectively copying the link itself. If
	<em class="parameter"><code>-H</code></em> is used, symbolic
	links specified as a parameter to <span class="command"><strong>cp</strong></span> may be
	followed, depending on the type and content of the file. If
	<em class="parameter"><code>-L</code></em> is used, symbolic
	links that were specified as a parameter to
	<span class="command"><strong>cp</strong></span> and symbolic links that were encountered
	while copying recursively may be followed, depending on the
	content of the file.
      </p>

      <p>
	If you want to preserve the ownership, SGID/SUID bits, and the
	modification and access times of a file, you can use the
	<em class="parameter"><code>-p</code></em> flag. This will try to preserve
	these properties in the file or directory copy. Good
	implementations of <span class="command"><strong>cp</strong></span> provide some
	additional protection as well - if the target file already
	exists, it may not be overwritten if the relevant metadata
	could not be preserved.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-managing-moving"></a>8.4.2. Moving files and directories</h3></div></div></div>
      

      <p>
	The UNIX command for moving files, <span class="command"><strong>mv</strong></span>, can
	move or rename files or directories. What actually happens
	depends on the location of the files or directories. If the
	source and destination files or directories are on the same
	filesystem, <span class="command"><strong>mv</strong></span> usually just creates new
	hard links, effectively renaming the files or directories. If
	both are on different filesystems, the files are actually
	copied, and the source files or directories are
	unlinked.
      </p>

      <p>
	The syntax of <span class="command"><strong>mv</strong></span> is comparable to
	<span class="command"><strong>cp</strong></span>. The most basic syntax renames
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file1</code></html:span> to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file2</code></html:span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>mv file1 file2</code></strong>
      </pre>

      <p>
	The same syntax can be used for two directories as well, which
	will rename the directory given as the first parameter to the
	second parameter.
      </p>

      <p>
	When the last parameter is an existing directory, the file or
	directory that is specified as the first parameter, is copied
	to that directory. In this case you can specify multiple files
	or directories as well. For instance:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>mkdir targetdir</code></strong>
$ <strong class="userinput"><code>mv file1 directory1 targetdir</code></strong>
      </pre>

      <p> This creates the directory <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">targetdir</code></html:span>, and moves
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file1</code></html:span> and <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">directory1</code></html:span> to this directory. </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-managing-removing"></a>8.4.3. Removing files and directories</h3></div></div></div>
      

      <p>
	Files and directories can be removed with the <span class="citerefentry">
          <span class="refentrytitle">rm</span>
          (1)
        </span> command. This command unlinks files and directories. If there are no other
        links to a file, its inode and disk blocks can be reclaimed for new files. Files can be
        removed by providing the files that should be removed as a parameter to <span class="citerefentry">
          <span class="refentrytitle">rm</span>
          (1)
        </span>. If the file is not writable, <span class="citerefentry">
          <span class="refentrytitle">rm</span>
          (1)
        </span> will ask for confirmation. For instance, to remove
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file1</code></html:span> and <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file2</code></html:span>, you can execute: </p>

      <pre class="screen">
$ <strong class="userinput"><code>rm file1 file2</code></strong>
      </pre>

      <p>
	If you have to remove a large number of files that require a confirmation before they
        can be deleted, or if you want to use <span class="citerefentry">
          <span class="refentrytitle">rm</span>
          (1)
        </span> to remove files from a script that will not be run on a terminal, add the
          <em class="parameter"><code>-f</code></em> parameter to override the use of prompts. Files
        that are not writable, are deleted with the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">-f</code></html:span> flag if the file
        ownership allows this. This parameter will also suppress printing of errors to
          <span class="emphasis"><em>stderr</em></span> if a file that should be removed was not found. </p>

      <p> Directories can be removed recursively as well with the <em class="parameter"><code>-r</code></em> parameter. <span class="citerefentry">
          <span class="refentrytitle">rm</span>
          (1)
        </span> will traverse the directory structure, unlinking and removing directories as
        they are encountered. The same semantics are used as when normal files are removed, as far
        as the <em class="parameter"><code>-f</code></em> flag is concerned. To give a short example,
        you can recursively remove all files and directories in the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">notes</code></html:span>
        directory with: </p>

      <pre class="screen">
$ <strong class="userinput"><code>rm -r notes</code></strong>
      </pre>

      

      <p> Since <span class="citerefentry">
          <span class="refentrytitle">rm</span>
          (1)
        </span> command uses the <span class="citerefentry">
          <span class="refentrytitle">unlink</span>
          (2)
        </span> function, data blocks are not rewritten to an uninitialized state. The
        information in data blocks is only overwritten when they are reallocated and used at a later
        time. To remove files including their data blocks securely, some systems provide a <span class="citerefentry">
          <span class="refentrytitle">shred</span>
          (1)
        </span> command that overwrites data blocks with random data. But this is not
        effective on many modern (journaling) filesystems, because they don't write data in place. </p>

      <p> The <span class="citerefentry">
          <span class="refentrytitle">unlink</span>
          (1)
        </span> commands provides a one on one implementation of the <span class="citerefentry">
          <span class="refentrytitle">unlink</span>
          (2)
        </span> function. It is of relatively little use, because it can not remove
        directories. </p>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-filesystem-permissions"></a>8.5. Permissions</h2></div></div></div>
    

    <p> We touched the subject of file and directory permissions in <a class="xref" href="#chap-filesystem-introduction-permissions" title="8.1.2. File permissions">Section 8.1.2, “File permissions”</a>. In this section, we will look at the <span class="citerefentry">
        <span class="refentrytitle">chown</span>
        (1)
      </span> and <span class="citerefentry">
        <span class="refentrytitle">chmod</span>
        (1)
      </span> commands, that are used to set the file ownership and permissions
      respectively. After that, we are going to look at a modern extension to permissions named
      Access Control Lists (ACLs). </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-permissions-ownership"></a>8.5.1. Changing the file ownership</h3></div></div></div>
      

      <p> As we have seen earlier, every file has an owner (user) ID and a group ID stored in the
        inode. The <span class="citerefentry">
          <span class="refentrytitle">chown</span>
          (1)
        </span> command can be used to set these fields. This can be done by the numeric
        IDs, or their names. For instance, to change the owner of the file
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">note.txt</code></html:span> to <span class="emphasis"><em>john</em></span>, and its group to
        <span class="emphasis"><em>staff</em></span>, the following command is used: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chown john:staff note.txt</code></strong>
      </pre>

      <p> You can also omit either components, to only set one of both fields. If you want to set
        the user name, you can also omit the colon. So, the command above can be split up in two
        steps: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chown john note.txt</code></strong>
$ <strong class="userinput"><code>chown :staff note.txt</code></strong>
      </pre>

      <p> If you want to change the owner of a directory, and all the files or directories it
        holds, you can add the <em class="parameter"><code>-R</code></em> to <span class="citerefentry">
          <span class="refentrytitle">chown</span>
          (1)
        </span>: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chown -R john:staff notes</code></strong>
      </pre>

      <p> If user and group names were specified, rather than IDs, the names are converted by <span class="citerefentry">
          <span class="refentrytitle">chown</span>
          (1)
        </span>. This conversion usually relies on the system-wide password database. If you
        are operating on a filesystem that uses another password database (e.g. if you mount a root
        filesystem from another system for recovery), it is often useful to change file ownership by
        the user or group ID. In this manner, you can keep the relevant user/group name to ID
        mappings in tact. So, changing the ownership of <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">note</code></html:span> to UID 1000 and
        GUID 1000 is done in the following (predictable) manner: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chown 1000:1000 note.txt</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-permissions-permbits"></a>8.5.2. Changing file permission bits</h3></div></div></div>
      

      <p> After reading the introduction to filesystem permissions in <a class="xref" href="#chap-filesystem-introduction-permissions" title="8.1.2. File permissions">Section 8.1.2, “File permissions”</a>, changing the permission bits that
        are stored in the inode is fairly easy with the <span class="citerefentry">
          <span class="refentrytitle">chmod</span>
          (1)
        </span> command. <span class="citerefentry">
          <span class="refentrytitle">chmod</span>
          (1)
        </span> accepts both numeric and symbolic representations of permissions.
        Representing the permissions of a file numerically is very handy, because it allows setting
        all relevant permissions tersely. For instance: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chmod 0644 note.txt</code></strong>
      </pre>

      <p> Make <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">note.txt</code></html:span> readable and writable for the owner of the file, and
        readable for the file group and others. </p>

      <p> Symbolic permissions work with addition or subtraction of rights, and allow for
        relative changes of file permissions. The syntax for symbolic permissions is: </p>

      <pre class="screen">
[ugo][-+][rwxst]
      </pre>

      <p> The first component specifies the user classes to which the permission change applies
        (user, group or other). Multiple characters of this component can be combined. The second
        component takes away rights (<span class="emphasis"><em>-</em></span>), or adds rights
        (<span class="emphasis"><em>+</em></span>). The third component is the access specifier (read, write, execute,
        set UID/GID on execution, sticky). Multiple components can be specified for this component
        too. Let's look at some examples to clear this up: </p>

      <pre class="screen">
ug+rw        # Give read/write rights to the file user and group
chmod go-x   # Take away execute rights from the file group and others.
chmod ugo-wx # Disallow all user classes to write to the file and to
             # execute the file.
      </pre>

      <p> These commands can be used in the following manner with chmod: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chmod ug+rw note.txt</code></strong>
$ <strong class="userinput"><code>chmod go-x script1.sh</code></strong>
$ <strong class="userinput"><code>chmod ugo-x script2.sh</code></strong>
      </pre>

      <p> Permissions of files and directories can be changed recursively with the <em class="parameter"><code>-R</code></em>. The following command makes the directory
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">notes</code></html:span> world-readable, including its contents: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chmod -R ugo+r notes</code></strong>
      </pre>

      <p> Extra care should be taken with directories, because the <span class="emphasis"><em>x</em></span> flag
        has a special meaning in a directory context. Users that have execute rights on directories
        can access a directory. User that don't have execute rights on directories can not. Because
        of this particular behavior, it is often easier to change the permissions of a directory
        structure and its files with help of the <span class="citerefentry">
          <span class="refentrytitle">find</span>
          (1)
        </span> command . </p>

      <p> There are a few extra permission bits that can be set that have a special meaning. The
        SUID and SGID are the most interesting bits of these extra bits. These bits change the
        active user ID or group ID to that of the owner or group of the file when the file is
        executed. The <span class="command"><strong>su(1)</strong></span> command is a good example of a file that usually has
        the SUID bit set: </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls -l /bin/su</code></strong>
-rwsr-xr-x  1 root root 60772 Aug 13 12:26 /bin/su
      </pre>

      <p> This means that the <span class="command"><strong>su</strong></span> command runs as the user
        <span class="emphasis"><em>root</em></span> when it is executed. The SUID bit can be set with the
        <span class="emphasis"><em>s</em></span> modifier. For instance, if the SUID bit was not set on
          <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/bin/su</code></html:span> this could be done with: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chmod u+s /bin/su</code></strong>
      </pre>

      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
        <p> Please be aware that the SUID and SGID bits have
        security implications. If a program with these bits set
        contain a bug, it may be exploited to get privileges of the
        file owner or group. For this reason it is good manner to keep
        the number of files with the SUID and SGID bits set to an
        absolute minimum. </p>
      </td></tr>
</table></div>

      <p> The sticky bit is also interesting when it comes to
      directory. It disallows users to rename or unlink files that
      they do not own, in directories that they do have write access
      to. This is usually used on world-writeable directories, like
      the temporary directory (<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/tmp</code></html:span>) on many UNIX
      systems. The sticky tag can be set with the
      <span class="emphasis"><em>t</em></span> modifier: </p>

      <pre class="screen">
$ <strong class="userinput"><code>chmod g+t /tmp</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-permissions-umask"></a>8.5.3. File creation mask</h3></div></div></div>
      

      <p>
	The question that remains is what initial permissions are used
	when a file is created.  This depends on two factors: the mode
	flag that was passed to the <span class="emphasis"><em>open(2)</em></span>
	system call, that is used to create a file, and the active
	file creation mask. The file creation mask can be represented
	as an octal number. The effective permissions for creating the
	file are determined as <span class="emphasis"><em>mode &amp;
	~mask</em></span>. Or, if represented in an octal fashion, you
	can substract the digits of the mask from the mode. For
	instance, if a file is created with permissions
	<span class="emphasis"><em>0666</em></span> (readable and writable by the file
	user, file group, and others), and the effective file creation
	mask is <span class="emphasis"><em>0022</em></span>, the effective file
	permission will be <span class="emphasis"><em>0644</em></span>. Let's look at
	another example. Suppose that files are still created with
	<span class="emphasis"><em>0666</em></span> permissions, and you are more
	paranoid, and want to take away all read and write permissions
	for the file group and others. This means you have to set the
	file creation mask to <span class="emphasis"><em>0066</em></span>, because
	substracting <span class="emphasis"><em>0066</em></span> from
	<span class="emphasis"><em>0666</em></span> yields
	<span class="emphasis"><em>0600</em></span>
      </p>
      
      <p>
        The effective file creation mask can be queried and set with
        the <span class="command"><strong>umask</strong></span> command, that is normally a
        built-in shell command. The effective mask can be printed by
        running <span class="command"><strong>umask</strong></span> without any parameters:
      </p>
      
      <pre class="screen">
$ <strong class="userinput"><code>umask</code></strong>
0002
      </pre>
      
      <p>
        The mask can be set by giving the octal mask number as a
        parameter. For instance:
      </p>
      
      <pre class="screen">
$ <strong class="userinput"><code>umask 0066</code></strong>
      </pre>
      
      <p>
        We can verify that this works by creating an empty file:
      </p>
      
      <pre class="screen">
$ <strong class="userinput"><code>touch test</code></strong>
$ <strong class="userinput"><code>ls -l test</code></strong>
-rw-------  1 daniel daniel 0 Oct 24 00:10 test2
      </pre>
      
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-permissions-acl"></a>8.5.4. Access Control Lists</h3></div></div></div>
      

      <p>
	Access Control lists (<acronym class="acronym">ACL</acronym>s) are an
	extension to traditional UNIX file permissions, that allow for
	more fine-grained access control. Most systems that support
	filesystem ACLs implement them as they were specified in the
	POSIX.1e and POSIX.2c draft specifications. Notable UNIX and
	UNIX-like systems that implement ACLs according to this draft
	are FreeBSD, Solaris, and Linux.
      </p>

      <p>
	As we have seen in <a class="xref" href="#chap-filesystem-introduction-permissions" title="8.1.2. File permissions">Section 8.1.2, “File permissions”</a> access
	control lists allows you to use read, write and execute
	triplets for additional users or groups. In contrast to the
	traditional file permissions, additional access control lists
	are not stored directly in the node, but in extended
	attributes that are associated with files. Two thing to be
	aware of when you use access control lists is that not all
	systems support them, and not all programs support them.
      </p>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-filesystem-permissions-acl-reading"></a>8.5.4.1. Reading access control lists</h4></div></div></div>
	

	<p>
	  On most systems that support ACLs, <span class="command"><strong>ls</strong></span>
	  uses a visual indicator to show that there are ACLs
	  associated with a file. For example:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>ls -l index.html</code></strong>
-rw-r-----+ 1 daniel daniel 3254 2006-10-31 17:11 index.html
	</pre>

	<p>
	  As you can see, the permissions column shows an additional
	  plus (<span class="emphasis"><em>+</em></span>) sign. The permission bits do
	  not quite act like you expect them to be. We will get to
	  that in a minute.
	</p>

	<p>
	  The ACLs for a file can be queried with the
	  <span class="command"><strong>getfacl</strong></span> command:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>getfacl index.html</code></strong>
# file: index.html
# owner: daniel
# group: daniel
user::rw-
group::---
group:www-data:r--
mask::r--
other::---
	</pre>

	<p>
	  Most lines can be interpreted very easily: the file user has
	  read/write permissions, the file group no permissions, users
	  of the group <span class="emphasis"><em>www-data</em></span> have read
	  permissions, and other users have no permissions. But why
	  does the group entry list no permissions for the file group,
	  while <span class="command"><strong>ls</strong></span> does? The secret is that if
	  there is a <span class="emphasis"><em>mask</em></span> entry,
	  <span class="command"><strong>ls</strong></span> displays the value of the mask, rather
	  than the file group permissions.
	</p>

	<p>
	  The <span class="emphasis"><em>mask</em></span> entry is used to restrict all
	  list entries with the exception of that of the file user,
	  and that for other users. It is best to memorize the
	  following rules for interpreting ACLs:
	</p>

	<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	    <p>
	      The <span class="emphasis"><em>user::</em></span> entry permissions
	      correspond with the permissions of the file owner.
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      The <span class="emphasis"><em>group::</em></span> entry permissions
	      correspond with the permissions of the file group,
	      unless there is a <span class="emphasis"><em>mask::</em></span> entry. If
	      there is a <span class="emphasis"><em>mask::</em></span> entry, the
	      permissions of the group correspond to the group
	      entry with the the mask entry as the maximum of allowed
	      permissions (meaning that the group restrictions can be
	      more restrictive, but not more permissive).
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      The permissions of other users and groups correspond to
	      their <span class="emphasis"><em>user:</em></span> and
	      <span class="emphasis"><em>group:</em></span> entries, with the value of
	      <span class="emphasis"><em>mask::</em></span> as their maximum
	      permissions.
	    </p>
	  </li>
</ul></div>

	<p>
	  The second and third rules can clearly be observed if there
	  is a user or group that has more rights than the mask for
	  the file:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>getfacl links.html</code></strong>
# file: links.html
# owner: daniel
# group: daniel
user::rw-
group::rw-                      #effective:r--
group:www-data:rw-              #effective:r--
mask::r--
other::---
	</pre>

	<p>
	  Although read and write permissions are specified for the
	  file and <span class="emphasis"><em>www-data</em></span> groups, both groups
	  will effectively only have read permission, because this is
	  the maximal permission that the mask allows.
	</p>

	<p>
	  Another aspect to pay attention to is the handling of ACLs
	  on directories. Access control lists can be added to
	  directories to govern access, but directories can also have
	  <span class="emphasis"><em>default ACLs</em></span> which specify the initial
	  ACLs for files and directories created under that directory.
	</p>

	<p>
	  Suppose that the directory <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">reports</code></html:span> has
	  the following ACL:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>getfacl reports</code></strong>
# file: reports
# owner: daniel
# group: daniel
user::rwx
group::r-x
group:www-data:r-x
mask::r-x
other::---
default:user::rwx
default:group::r-x
default:group:www-data:r-x
default:mask::r-x
default:other::---
	</pre>

	<p>
	  New files that are created in the
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">reports</code></html:span> directory get a ACL based on
	  the entries that have <span class="emphasis"><em>default:</em></span> as a
	  prefix. For example:
	</p>

	<pre class="screen">
$ touch reports/test
$ getfacl reports/test
# file: reports/test
# owner: daniel
# group: daniel
user::rw-
group::r-x                      #effective:r--
group:www-data:r-x              #effective:r--
mask::r--
other::---
	</pre>

	<p>
	  As you can see, the default ACL was copied. The execute bit
	  is removed from the mask, because the new file was not
	  created with execute permissions.
	</p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-filesystem-permissions-acl-setting"></a>8.5.4.2. Creating access control lists</h4></div></div></div>
	

	<p>
	  The ACL for a file or directory can be changed with the
	  <span class="command"><strong>setfacl</strong></span> program. Unfortunately, the
	  usage of this program highly depends on the system that
	  is being used. To add to that confusion, at least one
	  important flag (<em class="parameter"><code>-d</code></em>)
	  has a different meanings on different systems. One can
	  only hope that this command will get standardized.
	</p>

	<div class="table">
<a name="chap-filesystem-permissions-acl-setting-flags"></a><p class="title"><b>Table 8.4. System-specific <span class="command">setfacl</span> flags</b></p>
<div class="table-contents">
	  
	  
	  <table summary="System-specific setfacl flags" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Operation</th>
<th>Linux</th>
</tr></thead>
<tbody>
<tr>
<td>Set entries, removing all old entries</td>
<td><em class="parameter"><code>--set</code></em></td>
</tr>
<tr>
<td>Modify entries</td>
<td><em class="parameter"><code>-m</code></em></td>
</tr>
<tr>
<td>Modify default ACL entries</td>
<td><em class="parameter"><code>-d</code></em></td>
</tr>
<tr>
<td>Delete entry</td>
<td><em class="parameter"><code>-x</code></em></td>
</tr>
<tr>
<td>
		  Remove all ACL entries (except for the three
		  required entries).
		</td>
<td><em class="parameter"><code>-b</code></em></td>
</tr>
<tr>
<td>Recalculate mask</td>
<td>
		  Always recalculated, unless <em class="parameter"><code>-n</code></em> is used, or an mask
		  entry expicitly specified.
		</td>
</tr>
<tr>
<td>Use ACL specification from a file</td>
<td>
		  <em class="parameter"><code>-M</code></em> (modify),
		  <em class="parameter"><code>-X</code></em> (delete),
		  or <em class="parameter"><code>--restore</code></em>
		</td>
</tr>
<tr>
<td>Recursive modification of ACLs</td>
<td><em class="parameter"><code>-R</code></em></td>
</tr>
</tbody>
</table>
	</div>
</div>
<br class="table-break">

	<p>
	  As we have seen in the previous section, entries can be
	  specified for users and groups, by using the following
	  syntax:
	  <span class="emphasis"><em>user/group:name:permissions</em></span>. Permissions
	  can be specified as a triplet by using the letters
	  <span class="emphasis"><em>r</em></span> (read), <span class="emphasis"><em>w</em></span>
	  (write), or <span class="emphasis"><em>x</em></span> (execute). A dash
	  (<span class="emphasis"><em>-</em></span>) should be used for permissions that
	  you do not want to give to the user or group, since Solaris
	  requires this. If you want to disallow access completely,
	  you can use the <span class="emphasis"><em>---</em></span> triplet.
	</p>

	<p>
	  The specification for other users, and the mask
	  follows this format: <span class="emphasis"><em>other:r-x</em></span>. The
	  following slightly more predictable format can also be
	  used: <span class="emphasis"><em>other::r-x</em></span>.
	</p>

	<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="chap-filesystem-permissions-acl-setting-modify"></a>8.5.4.2.1. Modifying ACL entries</h5></div></div></div>
	  

	  <p>
	    The simplest operation is to modify an ACL entry. This
	    will create a new entry if the entry does not exist
	    yet. Entries can be modified with the <em class="parameter"><code>-m</code></em>. For instance, suppose that
	    we want to give the group <span class="emphasis"><em>friend</em></span> read
	    and write access to the file
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">report.txt</code></html:span>. This can be done with:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>setfacl -m group:friends:rw- report.txt</code></strong>
	  </pre>

	  <p>
	    The mask entry will be recalculated, setting it to the
	    union of all group entries, and additional user entries:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>getfacl report.txt</code></strong>
# file: report.txt
# owner: daniel
# group: daniel
user::rw-
group::r--
group:friends:rw-
mask::rw-
other::r--
	  </pre>

	  <p>
	    You can combine multiple ACL entries
	    by separating them with a comma character. For instance:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>setfacl -m group:friends:rw-,group:foes:--- report.txt</code></strong>
	  </pre>
	</div>

	<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="chap-filesystem-permissions-acl-setting-removing"></a>8.5.4.2.2. Removing ACL entries</h5></div></div></div>
	  

	  <p>
	    An entry can be removed with the <em class="parameter"><code>-x</code></em> option:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>setfacl -x group:friends: report.txt</code></strong>
	  </pre>

	  <p>
	    The trailing colon can optionally be omitted.
	  </p>
	</div>

	<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="chap-filesystem-permissions-acl-setting-new"></a>8.5.4.2.3. Making a new ACL</h5></div></div></div>
	  

	  <p>
	    The <em class="parameter"><code>--set</code></em> option
	    is provided create a new access control list
	    for a file, clearing all existing entries,
	    except for the three required entries.
	    It is required that the file user, group and
	    other entries are also specified. For example:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>setfacl --set user::rw-,group::r--,other:---,group:friends:rwx report.txt</code></strong>
	  </pre>

	  <p>
	    If you do not want to clean the user, group, and other
	    permissions, but do want to clear all other ACL entries,
	    you can use the <em class="parameter"><code>-b</code></em>
	    option. The following example uses this in combination
	    with the <em class="parameter"><code>-m</code></em> option
	    to clear all ACL entries (except for user, group, and other),
	    and to add an entry for the <span class="emphasis"><em>friends</em></span>
	    group:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>setfacl -b -m group:friends:rw- report.txt</code></strong>
	  </pre>
	</div>

	<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="chap-filesystem-permissions-acl-setting-default"></a>8.5.4.2.4. Setting a default ACL</h5></div></div></div>
	  

	  <p>
	    As we have seen in <a class="xref" href="#chap-filesystem-permissions-acl" title="8.5.4. Access Control Lists">Section 8.5.4, “Access Control Lists”</a>, directories
	    can have default ACL entries that specify what permissions
	    should be used for files and directories that are created
	    below that directory. The <em class="parameter"><code>-d</code></em>
	    option is used to operate on default entries:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>setfacl -d -m group:friends:rwx reports</code></strong>
$ <strong class="userinput"><code>getfacl reports</code></strong>
# file: reports
# owner: daniel
# group: daniel
user::rwx
group::r-x
other::r-x
default:user::rwx
default:group::r-x
default:group:friends:rwx
default:mask::rwx
default:other::r-x
	  </pre>
	</div>

	<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="chap-filesystem-permissions-acl-setting-filesource"></a>8.5.4.2.5. Using an ACL from a reference file</h5></div></div></div>
	  

	  <p>
	    You can also use an ACL specification from file, rather
	    than specifying it on the command line. An input file follows
	    the same
	    syntax as specifying entries as a parameter to
	    <span class="command"><strong>setfacl</strong></span>, but the entries are separated
	    by newlines, rather than by commas. This is very useful,
	    because you can use the ACL for an existing file as a
	    reference:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>getfacl report.txt &gt; ref</code></strong>
	  </pre>

	  <p>
	    The <em class="parameter"><code>-M</code></em> option
	    is provided to modify the ACL for a
	    file by reading the entries from a file. So, if we have a
	    file named <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">report2.txt</code></html:span>, we could
	    modify the ACL for this file with the entries from
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">ref</code></html:span> with:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>setfacl -M ref report2.txt</code></strong>
	  </pre>

	  <p>
	    If you would like to start with a clean ACL, and add the
	    entries from <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">ref</code></html:span>, you can add the
	    <em class="parameter"><code>-b</code></em> flag that we
	    encountered earlier:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>setfacl -b -M ref report2.txt</code></strong>
	  </pre>

	  <p>
	    Of course, it is not necessary to use this interim
	    file. We can directly pipe the output from
	    <span class="command"><strong>getfacl</strong></span> to <span class="command"><strong>setfacl</strong></span>,
	    by using the symbolic name for the standard input
	    (<span class="emphasis"><em>-</em></span>), rather than the name of a file:
	  </p>

	  <pre class="screen">
$ <strong class="userinput"><code>getfacl report.txt | setfacl -b -M - report2.txt</code></strong>
	  </pre>

	  <p>
	    The <em class="parameter"><code>-X</code></em> removes
	    the ACL entries defined in a file. This follows the same syntax as the
	    <em class="parameter"><code>-x</code></em> flag, with
	    commas replaced by newlines.
	  </p>
	</div>
      </div>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-filesystem-finding"></a>8.6. Finding files</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-finding-find"></a>8.6.1. find</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>find</strong></span> command is without doubt the most
	comprehensive utility to find files on UNIX systems. Besides
	that it works in a simple and predictable way:
	<span class="command"><strong>find</strong></span> will traverse the directory tree or
	trees that are specified as a parameter to
	<span class="command"><strong>find</strong></span>. Besides that a user can specify an
	expression that will be evaluated for each file and directory.
	The name of a file or directory will be printed if the
	expression evaluates to <span class="emphasis"><em>true</em></span>. The first
	argument that starts with a dash (<span class="emphasis"><em>-</em></span>),
	exclamation mark (<span class="emphasis"><em>!</em></span>, or an opening
	parenthesis (<span class="emphasis"><em>(</em></span>, signifies the start of
	the expression. The expression can consist of various
	operands.  To wrap it up, the syntax of
	<span class="command"><strong>find</strong></span> is: <span class="emphasis"><em>find paths
	expression</em></span>.
      </p>

      <p>
	The simplest use of <span class="command"><strong>find</strong></span> is to use no
	expression.  Since this matches every directory and subdirectory
	entry, all files and directories will be printed. For instance:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>find .</code></strong>
.
./economic
./economic/report.txt
./economic/report2.txt
./technical
./technical/report2.txt
./technical/report.txt
      </pre>

      <p>
	You can also specify multiple directories:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>find economic technical</code></strong>
economic
economic/report.txt
economic/report2.txt
technical
technical/report2.txt
technical/report.txt
      </pre>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-filesystem-finding-find-nametype"></a>8.6.1.1. Operands that limit by object name or type</h4></div></div></div>
	

	<p>
	  One common scenario for finding files or directories is to
	  look them up by name. The <span class="emphasis"><em>-name</em></span> operand
	  can be used to match objects that have a certain name, or
	  match a particular wildcard. For instance, using the operand
	  <span class="emphasis"><em>-name 'report.txt'</em></span> will only be true
	  for files or directories with the name
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">report.txt</code></html:span>. For example:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find economic technical -name 'report.txt'</code></strong>
economic/report.txt
technical/report.txt
	</pre>

	<p>
	  The same thing holds for wildcards:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find economic technical -name '*2.txt'</code></strong>
economic/report2.txt
technical/report2.txt
	</pre>

	<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
	  <p>
	    When using <span class="command"><strong>find</strong></span> you will want to pass
	    the wildcard to <span class="command"><strong>find</strong></span>, rather than
	    letting the shell expand it. So, make sure that patterns
	    are either quoted, or that wildcards are escaped.
	  </p>
	</td></tr>
</table></div>

	<p>
	  It is also possible to evaluate the type of the object with
	  the <span class="emphasis"><em>-type c</em></span> operand, where
	  <span class="emphasis"><em>c</em></span> specifies the type to be matched.
	  <a class="xref" href="#chap-filesystem-finding-find-nametype-type-params" title="Table 8.5. Parameters for the '-type' operand">Table 8.5, “Parameters for the '-type' operand”</a> lists the various object types that can be used.
	</p>

	<div class="table">
<a name="chap-filesystem-finding-find-nametype-type-params"></a><p class="title"><b>Table 8.5. Parameters for the '-type' operand</b></p>
<div class="table-contents">
	  

	  <table summary="Parameters for the '-type' operand" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Parameter</th>
<th>Meaning</th>
</tr></thead>
<tbody>
<tr>
<td>b</td>
<td>Block device file</td>
</tr>
<tr>
<td>c</td>
<td>Character device file</td>
</tr>
<tr>
<td>d</td>
<td>Directory</td>
</tr>
<tr>
<td>f</td>
<td>Regular file</td>
</tr>
<tr>
<td>l</td>
<td>Symbolic link</td>
</tr>
<tr>
<td>p</td>
<td>FIFO</td>
</tr>
<tr>
<td>s</td>
<td>Socket</td>
</tr>
</tbody>
</table>
	</div>
</div>
<br class="table-break">

	<p>
	  So, for instance, if you would like to match directories,
	  you could use the <span class="emphasis"><em>d</em></span> parameter to
	  <span class="emphasis"><em>-type</em></span> operand:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -type d</code></strong>
.
./economic
./technical
	</pre>

	<p>
	  We will look at forming a complex expression at the end of
	  this section about <span class="command"><strong>find</strong></span>, but at this
	  moment it is handy to know that you can make a boolean 'and'
	  expression by specifying multiple operands. For instance
	  <span class="emphasis"><em>operand1 operand2</em></span> is true if both
	  <span class="emphasis"><em>operand1</em></span> and
	  <span class="emphasis"><em>operand2</em></span> are true for the object that
	  is being evaluated. So, you could combine the
	  <span class="emphasis"><em>-name</em></span> and <span class="emphasis"><em>-type</em></span>
	  operands to find all directories that start with
	  <span class="emphasis"><em>eco</em></span>:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -name 'eco*' -type d</code></strong>
./economic
	</pre>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-filesystem-finding-find-perms"></a>8.6.1.2. Operands that limit by object ownership or permissions</h4></div></div></div>
	

	<p>
	  Besides matching objects by their name or type, you can also
	  match them by their active permissions or the object ownership.
	  This is often useful to find files that have incorrect permissions
	  or ownership.
	</p>

	<p>
	  The owner (user) or group of an object can be matched with
	  respectively the <span class="emphasis"><em>-user username</em></span> and
	  <span class="emphasis"><em>-group groupname</em></span> variants. The name of
	  a user or group will be interpreted as a user ID or group ID
	  if the name is decimal, and could not be found on the system
	  with
	  <span class="citerefentry"><span class="refentrytitle">getpwnam</span>(3)</span>
	  or
	  <span class="citerefentry"><span class="refentrytitle">getgrnam</span>(3)</span>. So,
	  if you would like to match all objects of which
	  <span class="emphasis"><em>joe</em></span> is the owner, you can use
	  <span class="emphasis"><em>-user joe</em></span> as an operand:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -user joe</code></strong>
./secret/report.txt
	</pre>

	<p>
	  Or to find all objects with the group
	  <span class="emphasis"><em>friend</em></span> as the file group:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -group friends</code></strong>
./secret/report.txt
	</pre>

	<p>
	  The operand for checking file permissions
	  <span class="emphasis"><em>-perm</em></span> is less trivial. Like the
	  <span class="command"><strong>chmod</strong></span> command this operator can work with
	  octal and symbolic permission notations. We will start with
	  looking at the octal notation. If an octal number is
	  specified as a parameter to the <span class="emphasis"><em>-perm</em></span>
	  operand, it will match all objects that have exactly that
	  permissions. For instance, <span class="emphasis"><em>-perm 0600</em></span>
	  will match all objects that are only readable and writable
	  by the user, and have no additional flags set:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -perm 0600</code></strong>
./secret/report.txt
	</pre>

	<p>
	  If a dash is added as a prefix to a number, it will match
	  every object that has at least the bits set that are
	  specified in the octal number. A useful example is to find
	  all files which have at least writable bits set for
	  <span class="emphasis"><em>other</em></span> users with <span class="emphasis"><em>-perm
	  -0002</em></span>. This can help you to find device nodes or
	  other objects with insecure permissions.
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find /dev -perm -0002</code></strong>
/dev/null
/dev/zero
/dev/ctty
/dev/random
/dev/fd/0
/dev/fd/1
/dev/fd/2
/dev/psm0
/dev/bpsm0
/dev/ptyp0
	</pre>

	<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
	  <p>
	    Some device nodes have to be world-writable for a UNIX
	    system to function correctly. For instance, the
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/null</code></html:span> device is always writable.
	  </p>
	</td></tr>
</table></div>

	<p>
	  The symbolic notation of <span class="emphasis"><em>-perm</em></span>
	  parameters uses the same notation as the
	  <span class="command"><strong>chmod</strong></span> command.  Symbolic permissions are
	  built with a file mode where all bits are cleared, so it is
	  never necessary to use a dash to take away rights. This also
	  prevents ambiguity that could arise with the dash
	  prefix. Like the octal syntax, prefixing the permission with
	  a dash will match objects that have at least the specified
	  permission bits set. The use of symbolic names is quite
	  predictable - the following two commands repeat the previous
	  examples with symbolic permissions:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -perm u+rw</code></strong>
./secret/report.txt
	</pre>

	<pre class="screen">
$ <strong class="userinput"><code>find /dev -perm -o+w</code></strong>
/dev/null
/dev/zero
/dev/ctty
/dev/random
/dev/fd/0
/dev/fd/1
/dev/fd/2
/dev/psm0
/dev/bpsm0
/dev/ptyp0
	</pre>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-filesystem-finding-find-time"></a>8.6.1.3. Operands that limit by object creation time</h4></div></div></div>
	

	<p>
	  There are three operands that operate on time intervals.
	  The syntax of the operand is <span class="emphasis"><em>operand n</em></span>,
	  where <span class="emphasis"><em>n</em></span> is the time in days. All three
	  operators calculate a time delta in seconds that is divided
	  by the the number of seconds in a day (86400), discarding
	  the remainder. So, if the delta is one day,
	  <span class="emphasis"><em>operand 1</em></span> will match for the
	  object. The three operands are:
	</p>

	<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>-atime n</em></span> - this operand evaluates
	      to true if the initialization time of <span class="command"><strong>find</strong></span>
	      minus the last access time of the object equals
	      to <span class="emphasis"><em>n</em></span>.
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>-ctime n</em></span> - this operand evaluates
	      to true if the initialization time of
	      <span class="command"><strong>find</strong></span> minus the time of the latest
	      change in the file status information equals to
	      <span class="emphasis"><em>n</em></span>.
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>-mtime n</em></span> - this operand evaluates
	      to true if the initialization time of
	      <span class="command"><strong>find</strong></span> minus the latest file change
	      time equals to <span class="emphasis"><em>n</em></span>.
	    </p>
	  </li>
</ul></div>

	<p>
	  So, these operands match if the latest access, change,
	  modification respectively was <span class="emphasis"><em>n</em></span> days
	  ago. To give an example, the following command shows all
	  objects in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc</code></html:span> that have been modified
	  one day ago:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find /etc -mtime 1</code></strong>
/etc
/etc/group
/etc/master.passwd
/etc/spwd.db
/etc/passwd
/etc/pwd.db
	</pre>

	<p>
	  The plus or minus sign can be used as modifiers for the meaning
	  of <span class="emphasis"><em>n</em></span>. <span class="emphasis"><em>+n</em></span> means more
	  than <span class="emphasis"><em>n</em></span> days, <span class="emphasis"><em>-n</em></span>
	  means less than <span class="emphasis"><em>n</em></span> days. So, to find all
	  files in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc</code></html:span> that were modified less
	  than two days ago, you could execute:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find /etc -mtime -2</code></strong>
/etc
/etc/network/run
/etc/network/run/ifstate
/etc/resolv.conf
/etc/default
/etc/default/locale
[...]
	</pre>

	<p>
	  Another useful time-based operand is the <span class="emphasis"><em>-newer
	  reffile</em></span> operand. This matches all files that were
	  modified later that the file with filename
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">reffile</code></html:span>. The following example shows how
	  you could use this to list all files that have later modification
	  times than <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">economic/report2.txt</code></html:span>:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -newer economic/report2.txt</code></strong>
.
./technical
./technical/report2.txt
./technical/report.txt
./secret
./secret/report.txt
	</pre>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-filesystem-finding-find-depth"></a>8.6.1.4. Operands that affect tree traversal</h4></div></div></div>
	

	<p>
	  Some operands affect the manner in which the
	  <span class="command"><strong>find</strong></span> command traverses the tree. The
	  first of these operands is the <span class="emphasis"><em>-xdev</em></span>
	  operand. <span class="emphasis"><em>-xdev</em></span> prevents that
	  <span class="command"><strong>find</strong></span> decends into directories that have a
	  different device ID, effectively avoiding traversal of other
	  filesystems. The directory to which the filesystem is
	  mounted, is printed, because this operand always returns
	  <span class="emphasis"><em>true</em></span>. A nice example is a system where
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr</code></html:span> is mounted on a different filesystem
	  than <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span>. For instance, if we search for
	  directories with the name <span class="emphasis"><em>bin</em></span>, this may
	  yield the following result:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find / -name 'bin' -type d</code></strong>
/usr/bin
/bin
	</pre>

	<p>
	  But if we add <span class="emphasis"><em>-xdev</em></span>
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/bin</code></html:span> is not found, because it is on
	  a different filesystem (and device):
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find / -name 'bin' -type d -xdev</code></strong>
/bin
	</pre>

	<p>
	  The <span class="emphasis"><em>-depth</em></span> operand modifies the order
	  in which directories are evaluated. With
	  <span class="emphasis"><em>-depth</em></span> the contents of a directory are
	  evaluated first, and then the directory itself. This can be
	  witnessed in the following example:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -depth</code></strong>
./economic/report.txt
./economic/report2.txt
./economic
./technical/report2.txt
./technical/report.txt
./technical
.
	</pre>

	<p>
	  As you can see in the output, files in the
	  <span class="emphasis"><em>./economic</em></span> directory is evaluated
	  before <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.</code></html:span>, and
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">./economic/report.txt</code></html:span> before
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">./economic</code></html:span>. <span class="emphasis"><em>-depth</em></span>
	  always evaluates to <span class="emphasis"><em>true</em></span>.
	</p>

	<p>
	  Finally, the <span class="emphasis"><em>-prune</em></span> operand causes find
	  not to decend into a directory that is being evaluated.
	  <span class="emphasis"><em>-prune</em></span> is discarded if the
	  <span class="emphasis"><em>-depth</em></span> operand is also
	  used. <span class="emphasis"><em>-prune</em></span> always evaluates to
	  <span class="emphasis"><em>true</em></span>.
	</p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-filesystem-finding-find-exec"></a>8.6.1.5. Operands that execute external utilities</h4></div></div></div>
	

	<p>
	  <span class="command"><strong>find</strong></span> becomes a very powerful tool when it
	  is combined with external utilities. This can be done with
	  the <span class="emphasis"><em>-exec</em></span> operand. There are two
	  syntaxes for the <span class="emphasis"><em>-exec</em></span> operand. The
	  first syntax is <span class="emphasis"><em>-exec utility arguments
	  ;</em></span>. The command <span class="emphasis"><em>utility</em></span> will
	  be executed with the arguments that were specified for each
	  object that is being evaluated. If any of the arguments is
	  <span class="emphasis"><em>{}</em></span>, these braces will be replaced by
	  the file being evaluated. This is very handy, especially when
	  we consider that, if we use no additional expression syntax,
	  operands will be evaluated from left to right. Let's look at
	  an example:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -perm 0666 -exec chmod 0644 {} \;</code></strong>
	</pre>

	<p>
	 The first operand returns true for files that have their
	 permissions set to <span class="emphasis"><em>0666</em></span>. The second
	 operand executes <span class="emphasis"><em>chmod 0644 filename</em></span> for
	 each file that is being evaluated. If you were wondering why
	 this command is not executed for every file, that is a good
	 question. Like many other interpreters of expressions,
	 <span class="command"><strong>find</strong></span> uses <span class="quote">“<span class="quote">short-circuiting</span>”</span>.
	 Because no other operator was specified, the logical
	 <span class="emphasis"><em>and</em></span> operator is automatically is assumed
	 between both operands. If the first operand evaluates to
	 <span class="emphasis"><em>false</em></span>, it makes no sense to evaluate any
	 further operands, because the complete expression will always
	 evaluate to false. So, the <span class="emphasis"><em>-exec</em></span> operand
	 will only be evaluated if the first operand is true. Another
	 particularity is that the semi-colon that closes the
	 <span class="emphasis"><em>-exec</em></span> is escaped, to prevent that the
	 shell parses it.
	</p>

	<p>
	  A nice thing about the <span class="emphasis"><em>-exec</em></span> operator
	  is that it evaluates to <span class="emphasis"><em>true</em></span> if the
	  command terminated sucessfully. So, you could also use
	  the <span class="emphasis"><em>-exec</em></span> command to add additional
	  conditions that are not represented by <span class="command"><strong>find</strong></span>
	  operands. For instance, the following command prints
	  all objects ending with <span class="emphasis"><em>.txt</em></span> that contain
	  the string <span class="emphasis"><em>gross income</em></span>:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -name '*.txt' -exec grep -q 'gross income' {} \; -print</code></strong>
./economic/report2.txt
	</pre>

	<p>
	  The <span class="command"><strong>grep</strong></span> command will be covered later on.
	   But for the moment, it is enough to know
	  that it can be used to match text patterns. The
	  <span class="emphasis"><em>-print</em></span> operand prints the current
	  object path. It is always used implicitly, except when the
	  <span class="emphasis"><em>-exec</em></span> or <span class="emphasis"><em>-ok</em></span>
	  operands are used. 
	</p>

	<p>
	  The second syntax of the <span class="emphasis"><em>-exec</em></span> operand
	  is <span class="emphasis"><em>-exec utility arguments {} +</em></span>. This
	  gathers a set of all matched object for which the expression
	  is true, and provides this set of files as an argument to
	  the utility that was specified. The first example of the
	  <span class="emphasis"><em>-exec</em></span> operand can also be written as:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . -perm 0666 -exec chmod 0644 {} +</code></strong>
	</pre>

	<p>
	  This will execute the <span class="command"><strong>chmod</strong></span> command only
	  once, with all files for which the expression is true as its
	  arguments. This operand always returns <span class="emphasis"><em>true</em></span>.
	</p>

	<p>
	  If a command executed by find returns a non-zero value
	  (meaning that the execution of the command was not
	  succesful), <span class="command"><strong>find</strong></span> should also return a
	  non-zero value.
	</p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-filesystem-finding-find-operators"></a>8.6.1.6. Operators for building complex expressions</h4></div></div></div>
	

	<p>
	  <span class="command"><strong>find</strong></span> provides some operators that can be
	  combined to make more complex expressions:
	</p>

	<div class="variablelist">
<p class="title"><b>Operators</b></p>
<dl class="variablelist">
<dt><span class="term">( expr )</span></dt>
<dd>
	      <p>
		Evaluates to <span class="emphasis"><em>true</em></span> if
		<span class="emphasis"><em>expr</em></span> evaluates to
		<span class="emphasis"><em>true</em></span>.
	      </p>
	    </dd>
<dt><span class="term">expr1 [-a] expr2</span></dt>
<dd>
	      <p>
		Evaluates to <span class="emphasis"><em>true</em></span> if both
		<span class="emphasis"><em>expr1</em></span> and <span class="emphasis"><em>expr2</em></span>
		are true. If <span class="emphasis"><em>-a</em></span> is omitted,
		this operator is implicitly assumed.
	      </p>

	      <p>
		<span class="command"><strong>find</strong></span> will use short-circuiting when
		this operator is evaluated: <span class="emphasis"><em>expr2</em></span>
		will not be evaluated when <span class="emphasis"><em>expr1</em></span>
		evaluates to <span class="emphasis"><em>false</em></span>
	      </p>
	    </dd>
<dt><span class="term">expr1 -o expr2</span></dt>
<dd>
	      <p>
		Evaluates to <span class="emphasis"><em>true</em></span> if either or
		both <span class="emphasis"><em>expr1</em></span> and
		<span class="emphasis"><em>expr2</em></span> are true.
	      </p>

	      <p>
		<span class="command"><strong>find</strong></span> will use short-circuiting when
		this operator is evaluated: <span class="emphasis"><em>expr2</em></span>
		will not be evaluated when <span class="emphasis"><em>expr1</em></span>
		evaluates to <span class="emphasis"><em>true</em></span>
	      </p>
	    </dd>
<dt><span class="term">! expr</span></dt>
<dd>
	      <p>
		Negates <span class="emphasis"><em>expr</em></span>. So, if
		<span class="emphasis"><em>expr</em></span> evaluates to true, this
		expression will evaluate to <span class="emphasis"><em>false</em></span>
		and vise versa.
	      </p>
	    </dd>
</dl>
</div>

	<p>
	  Since both the parentheses and exclamation mark characters
	  are interpreted by most shells, they should usually be
	  escaped.
	</p>

	<p>
	  The following example shows some operators in action. This
	  command executes <span class="command"><strong>chmod</strong></span> for all files that
	  either have their permissions set to
	  <span class="emphasis"><em>0666</em></span> or <span class="emphasis"><em>0664</em></span>.
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>find . \( -perm 0666 -o -perm 0664 \) -exec chmod 0644 {} \;</code></strong>
	</pre>
      </div>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-finding-which"></a>8.6.2. which</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>which</strong></span> command is not part of the Single
	UNIX Specification version 3, but it is provided by most
	sysmtems. <span class="command"><strong>which</strong></span> locates a command that is
	in the user's path (as set by the PATH environment variable),
	printing its full path. Providing the name of a command as its
	parameter will show the full path:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>which ls</code></strong>
/bin/ls
      </pre>

      <p>
	You can also query the paths of multiple commands:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>which ls cat</code></strong>
/bin/ls
/bin/cat
      </pre>

      <p>
        <span class="command"><strong>which</strong></span> returns a non-zero return value
	if the command could not be found.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-finding-whereis"></a>8.6.3. whereis</h3></div></div></div>
      

      <p>
	This <span class="command"><strong>whereis</strong></span> command searches binaries, manual pages and sources of a
	command in some predefined places. For instance, the following
	command shows the path of the <span class="command"><strong>ls</strong></span> and the
	<span class="citerefentry"><span class="refentrytitle">ls</span>(1)</span>
	manual page:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>whereis ls</code></strong>
ls: /bin/ls /usr/share/man/man1/ls.1.gz
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-filesystem-finding-locate"></a>8.6.4. locate</h3></div></div></div>
      

      <p>
        Slackware Linux also provides the
	<span class="command"><strong>locate</strong></span> command that searches through a file
	database that can be generated periodically with the
	<span class="command"><strong>updatedb</strong></span> command. Since it uses a prebuilt
	database of the filesystem, it is a lot faster than
	<span class="command"><strong>which</strong></span>, especially when directory entry
	information has not been cached yet. Though, the
	<span class="command"><strong>locate</strong></span>/<span class="command"><strong>updatedb</strong></span> combo
	has some downsides:
      </p>

      <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	  <p>
	    New files are not part of the database until the next
	    <span class="command"><strong>updatedb</strong></span> invocation.
	  </p>
	</li>
<li class="listitem">
	  <p>
	    <span class="command"><strong>locate</strong></span> has no conception of
	    permissions, so users may locate files that are normally
	    hidden to them.
	  </p>
	</li>
<li class="listitem">
	  <p>
	    A newer implementation, named <span class="emphasis"><em>slocate</em></span>
	    deals with permissions, but requires elevated privileges.
	    This is the <span class="command"><strong>locate</strong></span> variation that is
	    included with Slackware Linux.
	  </p>
	</li>
</ul></div>

      <p>
	With filesystems becoming faster, and by applying common sense
	when formulating <span class="command"><strong>find</strong></span> queries,
	<span class="command"><strong>locate</strong></span> does not really seem worth the
	hassle. Of course, your mileage may vary. That said, the basic
	usage of <span class="command"><strong>locate</strong></span> is <span class="emphasis"><em>locate
	filename</em></span>. For example:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>locate locate</code></strong>
/usr/bin/locate
/usr/lib/locate
/usr/lib/locate/bigram
/usr/lib/locate/code
/usr/lib/locate/frcode
[...]
      </pre>

    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="basics-filesystem-archives"></a>8.7. Archives</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="basics-filesystem-archives-introduction"></a>8.7.1. Introduction</h3></div></div></div>
      

      <p>
	Sooner or later a GNU/Linux user will encounter
	<acronym class="acronym">tar</acronym> archives, tar is the standard format
	for archiving files on GNU/Linux.  It is often used in
	conjunction with <span class="command"><strong>gzip</strong></span> or
	<span class="command"><strong>bzip2</strong></span>. Both commands can compress files and
	archives.  <a class="xref" href="#archive-extentions" title="Table 8.6. Archive file extensions">Table 8.6, “Archive file extensions”</a> lists
	frequently used archive extensions, and what they mean.
      </p>

      <div class="table">
<a name="archive-extentions"></a><p class="title"><b>Table 8.6. Archive file extensions</b></p>
<div class="table-contents">
	
	<table summary="Archive file extensions" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th align="left">Extension</th>
<th align="left">Meaning</th>
</tr></thead>
<tbody>
<tr>
<td align="left">.tar</td>
<td align="left">An uncompressed tar archive</td>
</tr>
<tr>
<td align="left">.tar.gz</td>
<td align="left">A tar archive compressed with gzip</td>
</tr>
<tr>
<td align="left">.tgz</td>
<td align="left">A tar archive compressed with gzip</td>
</tr>
<tr>
<td align="left">.tar.bz2</td>
<td align="left">A tar archive compressed with bzip2</td>
</tr>
<tr>
<td align="left">.tbz</td>
<td align="left">A tar archive compressed with bzip2</td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
	The difference between <span class="command"><strong>bzip2</strong></span> and
	<span class="command"><strong>gzip</strong></span> is that <span class="command"><strong>bzip2</strong></span> can
	find repeating information in larger blocks, resulting in
	better compression. But <span class="command"><strong>bzip2</strong></span> is also a lot
	slower, because it does more data analysis.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="basics-filesystem-archives-extracting"></a>8.7.2. Extracting archives</h3></div></div></div>
      

      <p>
	Since many software and data in the GNU/Linux world is
	archived with <span class="command"><strong>tar</strong></span> it is important to get
	used to extracting tar archives. The first thing you will
	often want to do when you receive a tar archive is to list its
	contents. This can be achieved by using the <em class="parameter"><code>t</code></em> parameter. However, if we just
	execute <span class="command"><strong>tar</strong></span> with this parameter and the
	name of the archive it will just sit and wait until you enter
	something to the standard input:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tar t test.tar</code></strong>
      </pre>

      <p>
	This happens because <span class="command"><strong>tar</strong></span> reads data from
	its standard input. If you forgot how redirection works, it is
	a good idea to reread <a class="xref" href="#chap-shell-inout" title="7.7. Redireccions i canonades">Section 7.7, “Redireccions i canonades ”</a>. Let's
	see what happens if we redirect our tar archive to tar:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tar t &lt; test.tar</code></strong>
test/
test/test2
test/test1
      </pre>

      <p>
	That looks more like the output you probably expected. This
	archive seems to contain a directory
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">test</code></html:span>, which contains the files
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">test2</code></html:span> and <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">test1</code></html:span>.  It
	is also possible to specify the archive file name as an
	parameter to <span class="command"><strong>tar</strong></span>, by using the <em class="parameter"><code>f</code></em> parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tar tf test.tar</code></strong>
test/
test/test2
test/test1
      </pre>

      <p>
	This looks like an archive that contains useful files ;). We
	can now go ahead, and extract this archive by using the
	<em class="parameter"><code>x</code></em> parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tar xf test.tar</code></strong>
      </pre>

      <p>
	We can now verify that tar really extracted the archive by
	listing the contents of the directory with
	<span class="command"><strong>ls</strong></span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ls test/</code></strong>
test1  test2
      </pre>

      <p>
	Extracting or listing files from a gzipped or bzipped archive
	is not much more difficult. This can be done by adding a
	<em class="parameter"><code>z</code></em> or <em class="parameter"><code>j</code></em> for respectively archives
	compressed with <span class="command"><strong>gzip</strong></span> or
	<span class="command"><strong>bzip2</strong></span>.  For example, we can list the
	contents of a gzipped archive with:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tar ztf archive2.tar.gz</code></strong>
      </pre>

      <p>
	And a bzipped archive can be extracted with:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tar jxf archive3.tar.bz2</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="basics-filesystem-archives-creating"></a>8.7.3. Creating archives</h3></div></div></div>
      

      <p>
	You can create archives with the <em class="parameter"><code>c</code></em> parameter. Suppose that we have
	the directory <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">test</code></html:span> shown in the previous
	example. We can make an archive with the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">test</code></html:span> directory and the files in this
	directory with:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tar cf important-files.tar test</code></strong>
      </pre>

      <p>
	This will create the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">important-files.tar</code></html:span>
	archive (which is specified with the <em class="parameter"><code>f</code></em> parameter). We can now verify
	the archive:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tar tf important-files.tar</code></strong>
test/
test/test2
test/test1
      </pre>

      <p>
	Creating a gzipped or bzipped archive goes along the same
	lines as extracting compressed archives: add a <em class="parameter"><code>z</code></em> for gzipping an archive, or
	<em class="parameter"><code>b</code></em> for bzipping an
	archive. Suppose that we wanted to create a
	<span class="command"><strong>gzip</strong></span> compressed version of the archive
	created above. We can do this with:
      </p>

      <pre class="screen">
<strong class="userinput"><code>tar zcf important-files.tar.gz test</code></strong>
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="basics-filesystem-mounting"></a>8.8. Mounting filesystems</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="basics-filesystem-mounting-introduction"></a>8.8.1. Introduction</h3></div></div></div>
      

      <p>
	Like most Unices Linux uses a technique named
	<span class="quote">“<span class="quote">mounting</span>”</span> to access filesystems. Mounting means
	that a filesystem is connected to a directory in the root
	filesystem. One could for example mount a CD-ROM drive to the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt/cdrom</code></html:span> directory. Linux supports many
	kinds of filesystems, like Ext2, Ext3, ReiserFS, JFS, XFS,
	ISO9660 (used for CD-ROMs), UDF (used on some DVDs) and
	DOS/Windows filesystems, like FAT, FAT32 and NTFS. These
	filesystems can reside on many kinds of media, for example
	hard drives, CD-ROMs and Flash drives. This section explains
	how filesystems can be mounted and unmounted.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="basics-filesystem-mounting-mount"></a>8.8.2. mount</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>mount</strong></span> is used to mount filesystems. The
	basic syntax is: <span class="quote">“<span class="quote">mount /dev/devname
	/mountpoint</span>”</span>. The device name can be any block device,
	like hard disks or CD-ROM drives. The mount point can be an
	arbitrary point in the root filesystem. Let's look at an
	example:
      </p>

      <pre class="screen">
# <strong class="userinput"><code>mount /dev/cdrom /mnt/cdrom</code></strong>
      </pre>

      <p>
	This mounts the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/cdrom</code></html:span> on the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt/cdrom</code></html:span> mountpoint. The
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/cdrom</code></html:span> device name is normally a link
	to the real CD-ROM device name (for example,
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hdc</code></html:span>). As you can see, the concept is
	actually very simple, it just takes some time to learn the
	device names ;). Sometimes it is necessary to specify which
	kind of filesystem you are trying to mount.  The filesystem
	type can be specified by adding the <em class="parameter"><code>-t</code></em> parameter:
      </p>

      <pre class="screen">
# <strong class="userinput"><code>mount -t vfat /dev/sda1 /mnt/flash</code></strong>
      </pre>

      <p>
	This mounts the vfat filesystem on
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/sda1</code></html:span> to
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt/flash</code></html:span>.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="basics-filesystem-mounting-umount"></a>8.8.3. umount</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>umount</strong></span> command is used to unmount
	filesystems.  <span class="command"><strong>umount</strong></span> accepts two kinds of
	parameters, mount points or devices. For example:
      </p>

      <pre class="screen">
# <strong class="userinput"><code>umount /mnt/cdrom</code></strong>
# <strong class="userinput"><code>umount /dev/sda1</code></strong>
      </pre>

      <p>
	The first command unmounts the filesystem that was mounted on
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt/cdrom</code></html:span>, the second commands unmounts
	the filesystem on <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/sda1</code></html:span>.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="basics-filesystem-mounting-fstab"></a>8.8.4. The fstab file</h3></div></div></div>
      

      <p>
	The GNU/Linux system has a special file,
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/fstab</code></html:span>, that specifies which
	filesystems should be mounted during the system boot.  Let's
	look at an example:
      </p>

      <pre class="screen">
/dev/hda10       swap             swap        defaults         0   0
/dev/hda5        /                xfs         defaults         1   1
/dev/hda6        /var             xfs         defaults         1   2
/dev/hda7        /tmp             xfs         defaults         1   2
/dev/hda8        /home            xfs         defaults         1   2
/dev/hda9        /usr             xfs         defaults         1   2
/dev/cdrom       /mnt/cdrom       iso9660     noauto,owner,ro  0   0
/dev/fd0         /mnt/floppy      auto        noauto,owner     0   0
devpts           /dev/pts         devpts      gid=5,mode=620   0   0
proc             /proc            proc        defaults         0   0
      </pre>

      <p>
	As you can see each entry in the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">fstab</code></html:span>
	file has five entries: fs_spec, fs_file, fs_vfstype,
	fs_mntops, fs_freq, and fs_passno.  We are now going to look
	at each entry.
      </p>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm951048380"></a>8.8.4.1. fs_spec</h4></div></div></div>
	

	<p>
	  The fs_spec option specifies the block device, or remote
	  filesystem that should be mounted. As you can see in the
	  example several /dev/hda partitions are specified, as well
	  as the CD-ROM drive and floppy drive. When NFS volumes are
	  mounted an IP address and directory can be specified, for
	  example: <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">192.168.1.10:/exports/data</code></html:span>.
	</p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm951047068"></a>8.8.4.2. fs_file</h4></div></div></div>
	

	<p>
	  fs_file specifies the mount point. This can be an arbitrary
	  directory in the filesystem.
	</p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm951046372"></a>8.8.4.3. fs_vfstype</h4></div></div></div>
	

	<p>
	  This option specifies what kind of filesystem the entry
	  represents. For example this can be: ext2, ext3, reiserfs,
	  xfs, nfs, vfat, or ntfs.
	</p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm951045556"></a>8.8.4.4. fs_mntops</h4></div></div></div>
	

	<p>
	  The fs_mntops option specifies which parameters should be
	  used for mounting the filesystem. The
	  <span class="command"><strong>mount</strong></span> manual page has an extensive
	  description of the available options. These are the most
	  interesting options:
	</p>

	<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>noauto</em></span>: filesystems that are listed
	      in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/fstab</code></html:span> are normally mounted
	      automatically. When the <span class="quote">“<span class="quote">noauto</span>”</span> option is
	      specified, the filesystem will not be mounted during the
	      system boot, but only after issuing a
	      <span class="command"><strong>mount</strong></span> command. When mounting such
	      filesystem, only the mount point or device name has to
	      be specified, for example: <span class="command"><strong>mount
	      /mnt/cdrom</strong></span>
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>user</em></span>: adding the
	      <span class="quote">“<span class="quote">user</span>”</span> option will allow normal users to
	      mount the filesystem (normally only the superuser is
	      allowed to mount filesystems).
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>owner</em></span>: the <span class="quote">“<span class="quote">owner</span>”</span>
	      option will allow the owner of the specified device to
	      mount the specified device. You can see the owner of a
	      device using <span class="command"><strong>ls</strong></span>, e.g.  <span class="command"><strong>ls -l
	      /dev/cdrom</strong></span>.
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>noexec</em></span>: with this option enabled
	      users can not run files from the mounted
	      filesystem. This can be used to provide more security.
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>nosuid</em></span>: this option is comparable
	      to the <span class="quote">“<span class="quote">noexec</span>”</span> option. With
	      <span class="quote">“<span class="quote">nosuid</span>”</span> enabled SUID bits on files on the
	      filesystem will not be allowed. SUID is used for certain
	      binaries to provide a normal user to do something
	      privileged.  This is certainly a security threat, so
	      this option should really be used for removable media,
	      etc. A normal user mount will force the nosuid option,
	      but a mount by the superuser will not!
	    </p>
	  </li>
<li class="listitem">
	    <p>
	      <span class="emphasis"><em>unhide</em></span>: this option is only
	      relevant for normal CD-ROMs with the ISO9660
	      filesystem. If <span class="quote">“<span class="quote">unhide</span>”</span> is specified hidden
	      files will also be visible.
	    </p>
	  </li>
</ul></div>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm951036236"></a>8.8.4.5. fs_freq</h4></div></div></div>
	

	<p>
	  If the <span class="quote">“<span class="quote">fs_freq</span>”</span> is set to 1 or higher, it
	  specifies after how many days a filesystem dump (backup) has
	  to be made. This option is only used when <a class="ulink" href="http://dump.sourceforge.net/" target="_top">dump</a> is
	  installed, and set up correctly to handle this.
	</p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idm951035260"></a>8.8.4.6. fs_passno</h4></div></div></div>
	

	<p>
	  This field is used by <span class="command"><strong>fsck</strong></span> to determine
	  the order in which filesystems are checked during the system
	  boot.
	</p>
      </div>
    </div>

  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="basics-filesystem-gnupg"></a>8.9. Encrypting and signing files</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm951033308"></a>8.9.1. Introduction</h3></div></div></div>
      

      <p>
	There are two security mechanisms for securing files: signing
	files and encrypting files. Signing a file means that a
	special digital signature is generated for a file. You, or
	other persons can use the signature to verify the integrity of
	the file. File encryption encodes a file in a way that only a
	person for which the file was intended to read can read the
	file.
      </p>

      <p>
	This system relies on two keys: the private and the public
	key. Public keys are used to encrypt files, and files can only
	be decrypted with the private key. This means that one can
	sent his public key out to other persons. Others can use this
	key to send encrypted files, that only the person with the
	private key can decode. Of course, this means that the
	security of this system depends on how well the private is
	kept secret.
      </p>

      <p>
	Slackware Linux provides an excellent tool for signing and
	encrypting files, named GnuPG. GnuPG can be installed from the
	<span class="quote">“<span class="quote">n</span>”</span> disk set.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm951031060"></a>8.9.2. Generating your private and public keys</h3></div></div></div>
      

      <p>
	Generating public and private keys is a bit complicated,
	because GnuPG uses DSA keys by default. DSA is an encryption
	algorithm, the problem is that the maximum key length of DSA
	is 1024 bits, this is considered too short for the longer
	term. That is why it is a good idea to use 2048 bit RSA
	keys. This section describers how this can be done.
      </p>

      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
	<p>
	  1024-bit keys were believed to be secure for a long
	  time. But Bernstein's paper <span class="emphasis"><em>Circuits for Integer
	  Factorization: a Proposal</em></span> contests this, the
	  bottom line is that it is quite feasible for national
	  security agencies to produce hardware that can break keys in
	  a relatively short amount of time.  Besides that it has be
	  shown that 512-bit RSA keys can be broken in a relatively
	  short time using common hardware. More information about
	  these issues can by found in this e-mail to the cypherpunks
	  list:
	<a class="ulink" href="http://tin.le.org/vault/security/encryption/rsa1024.html" target="_top">http://tin.le.org/vault/security/encryption/rsa1024.html</a>
	</p>
      </td></tr>
</table></div>

      <p>
	We can generate a key by executing:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --gen-key</code></strong>
      </pre>

      <p>
	The first question is what kind of key you would like to
	make. We will choose <span class="emphasis"><em>(4) RSA (sign only)</em></span>:
      </p>

      <pre class="screen">
Please select what kind of key you want:
   (1) DSA and ElGamal (default)
   (2) DSA (sign only)
   (4) RSA (sign only)
Your selection? <strong class="userinput"><code>4</code></strong>
      </pre>

      <p>
	You will then be asked what the size of the key you want to
	generate has to be. Type in <span class="emphasis"><em>2048</em></span> to
	generate a 2048 bit key, and press enter to continue.
      </p>

      <pre class="screen">
What keysize do you want? (1024) <strong class="userinput"><code>2048</code></strong>
      </pre>

      <p>
	The next question is simple to answer, just choose what you
	like. Generally speaking it is not a bad idea to let the key
	be valid infinitely. You can always deactivate the key with a
	special revocation certificate.
      </p>

      <pre class="screen">
Please specify how long the key should be valid.
         0 = key does not expire
      &lt;n&gt;  = key expires in n days
      &lt;n&gt;w = key expires in n weeks
      &lt;n&gt;m = key expires in n months
      &lt;n&gt;y = key expires in n years
Key is valid for? (0) <strong class="userinput"><code>0</code></strong>
      </pre>

      <p>
	GnuPG will then ask for confirmation. After confirming your
	name and e-mail address will be requested. GnuPG will also ask
	for a comment, you can leave this blank, or you could fill in
	something like <span class="quote">“<span class="quote">Work</span>”</span> or <span class="quote">“<span class="quote">Private</span>”</span>,
	to indicate what the key is used for. For example:
      </p>

      <pre class="screen">
Real name: <strong class="userinput"><code>John Doe</code></strong>
Email address: <strong class="userinput"><code>john@doe.com</code></strong>
Comment: <strong class="userinput"><code>Work</code></strong>              
You selected this USER-ID:
    "John Doe (Work) &lt;john@doe.com&gt;"
      </pre>

      <p>
	GnuPG will the ask you to confirm your user ID. After
	confirming it GnuPG will ask you to enter a password. Be sure
	to use a good password:
      </p>

      <pre class="screen">
You need a Passphrase to protect your secret key.    

Enter passphrase:
      </pre>

      <p>
	After entering the password twice GnuPG will generate the
	keys. But we are not done yet. GnuPG has only generated a key
	for signing information, not for encryption of information. To
	continue, have a look at the output, and look for the key
	ID. In the information about the key you will see
	<span class="emphasis"><em>pub 2048R/</em></span>. The key ID is printed after
	this fragment.  In this example:
      </p>

      <pre class="screen">
public and secret key created and signed.
key marked as ultimately trusted.

pub  2048R/8D080768 2004-07-16 John Doe (Work) &lt;john@doe.com&gt;
     Key fingerprint = 625A 269A 16B9 C652 B953  8B64 389A E0C9 8D08 0768
      </pre>

      <p>
	the key ID is <span class="emphasis"><em>8D080768</em></span>. If you lost the
	output of the key generation you can still find the key ID in
	the output of the <span class="command"><strong>gpg --list-keys</strong></span>
	command. Use the key ID to tell GnuPG that you want to edit
	your key:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --edit-key &lt;Key ID&gt;</code></strong>
      </pre>

      <p>
	With the example key above the command would be:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --edit-key 8D080768</code></strong>
      </pre>

      <p>
	GnuPG will now display a command prompt. Execute the
	<span class="command"><strong>addkey</strong></span> command on this command prompt:
      </p>

      <pre class="screen">
Command&gt; <strong class="userinput"><code>addkey</code></strong>
      </pre>

      <p>
	GnuPG will now ask the password you used for your key:
      </p>

      <pre class="screen">
Key is protected.

You need a passphrase to unlock the secret key for
user: "John Doe (Work) &lt;john@doe.com&gt;"
2048-bit RSA key, ID 8D080768, created 2004-07-16

Enter passphrase:
      </pre>

      <p>
	After entering the password GnuPG will ask you what kind of
	key you would like to create. Choose <span class="emphasis"><em>RSA (encrypt
	only)</em></span>, and fill in the information like you did
	earlier (be sure to use a 2048 bit key).  For example:
      </p>

      <pre class="screen">
Please select what kind of key you want:
   (2) DSA (sign only)
   (3) ElGamal (encrypt only)
   (4) RSA (sign only)
   (5) RSA (encrypt only)
Your selection? <strong class="userinput"><code>5</code></strong>
What keysize do you want? (1024) <strong class="userinput"><code>2048</code></strong>
Requested keysize is 2048 bits       
Please specify how long the key should be valid.
         0 = key does not expire
      &lt;n&gt;  = key expires in n days
      &lt;n&gt;w = key expires in n weeks
      &lt;n&gt;m = key expires in n months
      &lt;n&gt;y = key expires in n years
Key is valid for? (0) <strong class="userinput"><code>0</code></strong>
      </pre>

      <p>
	And confirm that the information is correct. After the key is
	generated you can leave the GnuPG command prompt, and save the
	new key with the <span class="command"><strong>save</strong></span> command:
      </p>

      <pre class="screen">
Command&gt; <strong class="userinput"><code>save</code></strong>
      </pre>

      <p>
	Congratulations! You have now generated the necessary keys to
	encrypt and decrypt e-mails and files. You can now configure
	your e-mail client to use GnuPG. It is a good idea to store
	the contents of the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.gnupg</code></html:span> directory on
	some reliable medium, and store that in a safe place! If your
	private key is lost you can't decrypt files and messages that
	were encrypted with your public key. If the private key, and
	your password are stolen, the security of this system is
	completely compromised.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm951012908"></a>8.9.3. Exporting your public key</h3></div></div></div>
      

      <p>
	To make GnuPG useful, you have to give your public key to
	people who send you files or e-mails. They can use your public
	key to encrypt files, or use it to verify whether a file has a
	correct signature or not. The key can be exported using the
	<em class="parameter"><code>--export</code></em> parameter. It
	is also a good idea to specify the <em class="parameter"><code>--output</code></em> parameter, this will save
	the key in a file. The following command would save the public
	key of <span class="emphasis"><em>John Doe</em></span>, used in earlier
	examples, to the file <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">key.gpg</code></html:span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --output key.gpg --export john@doe.com</code></strong>
      </pre>

      <p>
	This saves the key in binary format. Often it is more
	convenient to use the so-called <span class="quote">“<span class="quote">ASCII armored
	output</span>”</span>, which fits better for adding the key to
	e-mails, or websites. You export an ASCII armored version of
	the key by adding the <em class="parameter"><code>--armor</code></em> parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --armor --output key.gpg --export john@doe.com</code></strong>
      </pre>

      <p>
	If you look at the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">key.gpg</code></html:span> file you will
	notice that the ASCII armored key is a much more comfortable
	format.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm951009532"></a>8.9.4. Signatures</h3></div></div></div>
      

      <p>
	With GPG you can make a signature for a file. This signature
	is unique, because your signature can only be made with your
	private key. This means that other people can check whether
	the file was really sent by you, and whether it was in any way
	altered or not. Files can be signed with the <em class="parameter"><code>--detach-sign</code></em> parameter. Let us
	look at an example. This command will make a signature for the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">memo.txt</code></html:span> file. The signature will be
	stored in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">memo.txt.sig</code></html:span>.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --output memo.txt.sig --detach-sign memo.txt</code></strong>

You need a passphrase to unlock the secret key for
user: "John Doe (Work) &lt;john@doe.com&gt;"
2048-bit RSA key, ID 8D080768, created 2004-07-16

Enter passphrase:
      </pre>

      <p>
	As you can see, GnuPG will ask you to enter the password for
	your private key. After you have entered the right password the
	signature file (<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">memo.txt.sig</code></html:span>) will be
	created.
      </p>

      <p>
	You can verify a file with its signature using the <em class="parameter"><code>--verify</code></em> parameter. Specify the
	signature file as a parameter to the <em class="parameter"><code>--verify</code></em> parameter. The file that
	needs to be verified can be specified as the final parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --verify memo.txt.sig memo.txt</code></strong>
gpg: Signature made Tue Jul 20 23:47:45 2004 CEST using RSA key ID 8D080768
gpg: Good signature from "John Doe (Work) &lt;john@doe.com&gt;"
      </pre>

      <p>
	This will confirm that the file was indeed signed by
	<span class="emphasis"><em>John Doe (Work) &lt;john@doe.com&gt;</em></span>,
	with the key <span class="emphasis"><em>8D080768</em></span>, and that the file
	is unchanged. Suppose the file was changed, GnuPG would have
	complained about it loudly:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --verify memo.txt.sig memo.txt</code></strong>
gpg: Signature made Tue Jul 20 23:47:45 2004 CEST using RSA key ID 8D080768
gpg: BAD signature from "John Doe (Work) &lt;john@doe.com&gt;"
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm951002236"></a>8.9.5. Encryption</h3></div></div></div>
      

      <p>
	One of the main features of GnuPG is encryption. Due to its
	use of asymmetric cryptography, the person who encrypts a file
	and the person who decrypts a file do not need to share a
	key. You can encrypt a file with the public key of another
	person, and that other person can decrypt it with his or her
	private key. You can encrypt files with the <em class="parameter"><code>--encrypt</code></em>. If you do not specify a
	user ID for which the file should be encrypted, GnuPG will
	prompt for the user ID. You can specify the user ID with the
	<em class="parameter"><code>-r</code></em> parameter. In the
	following example, the file <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">secret.txt</code></html:span>
	will be encrypted for another person named <span class="emphasis"><em>John
	Doe</em></span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --encrypt -r "John Doe" secret.txt</code></strong>
      </pre>

      <p>
	The user ID is quoted with double quotes for making sure that
	the ID is interpreted as a single program argument. After the
	encryption is completed, the encrypted version of the file
	will be available as <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">secret.txt.gpg</code></html:span>.
      </p>

      <p>
	The user who receives the file can decrypt it with the
	<em class="parameter"><code>--decrypt</code></em> parameter of
	the <span class="command"><strong>gpg</strong></span> command:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>gpg --output secret.txt --decrypt secret.txt.gpg</code></strong>

You need a passphrase to unlock the secret key for
user: "John Doe (Work) &lt;john@doe.com&gt;"
2048-bit RSA key, ID 8D080768, created 2004-07-16 (main key ID EC3ED1AB)

Enter passphrase:

gpg: encrypted with 2048-bit RSA key, ID 8D080768, created 2004-07-16
      "John Doe (Work) &lt;john@doe.com&gt;"
      </pre>

      <p>
	In this example the <em class="parameter"><code>--output</code></em> parameter is used store
	the decrypted content in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">secret.txt</code></html:span>.
      </p>
    </div>
  </div>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.idm951380196" class="footnote">
	<p><a href="#idm951380196" class="para"><sup class="para">[4] </sup></a>At the time of writing, ACLs were supported on ext2,
        ext3, and XFS filesystems</p> </div>
<div id="ftn.idm951348060" class="footnote">
          <p><a href="#idm951348060" class="para"><sup class="para">[5] </sup></a>Yeah, you can be creative with magic numbers
          too!</p> </div>
</div>
</div>
    <div lang="en" class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-textproc"></a>Chapter 9. Text processing</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-textproc-simple">9.1. Simple text manipulation</a></span></dt>
<dt><span class="sect1"><a href="#chap-textproc-regexps">9.2. Regular expressions</a></span></dt>
<dt><span class="sect1"><a href="#chap-textproc-grep">9.3. grep</a></span></dt>
</dl>
</div>
  

  <p>
    Text manipulation is one of the things that UNIX excels at,
    because it forms the heart of the UNIX philosophy, as described in
    <a class="xref" href="#chap-intro-unix" title="2.4. La filosofia UNIX">Section 2.4, “La filosofia UNIX”</a>. Most UNIX commands
    are simple programs that read data from the standard input,
    performs some operation on the data, and sends the result to the
    program's standard output. These programs basically act as an
    filters, that can be connected as a pipeline. This allows the user
    to put the UNIX tools to uses that the writers never
    envisioned. In later chapters we will see how you can build simple
    filters yourself. 
  </p>

  <p>
    This chapter describes some simple, but important, UNIX commands
    that can be used to manipulate text. After that, we will dive into
    regular expressions, a sublanguage that can be used to match text
    patterns.
  </p>
 
  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-textproc-simple"></a>9.1. Simple text manipulation</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-simple-cat"></a>9.1.1. Repeating what is said</h3></div></div></div>
      

      <p>
	The most simple text filter is the <span class="command"><strong>cat</strong></span>, it
	does nothing else than sending the data from stdin to stdout:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>echo "hello world" | cat</code></strong>
hello world
      </pre>

      <p>
	Another useful feature is that you can let it send the contents
	of a file to the standard output:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat file.txt</code></strong>
Hello, this is the content of file.txt
      </pre>

      <p>
	<span class="command"><strong>cat</strong></span> really lives up to its name when
	multiple files are added as arguments. This will concatenate
	the files, in the sense that it will send the contents of all
	files to the standard output, in the same order as they were
	specified as an argument. The following screen snippet
	demonstrates this:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat file.txt file1.txt file2.txt</code></strong>
Hello, this is the content of file.txt
Hello, this is the content of file1.txt
Hello, this is the content of file2.txt
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-simple-wc"></a>9.1.2. Text statistics</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>wc</strong></span> command provides statistics about a
	text file or text stream. Without any parameters, it will
	print the number of lines, the number of words, and the number
	of bytes respectively. A word is delimited by one white space
	character, or a sequence of whitespace characters.
      </p>

      <p>
	The following example shows the number of lines, words, and
	bytes in the canonical <span class="quote">“<span class="quote">Hello world!</span>”</span> example:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>echo "Hello world!" | wc</code></strong> 
       1       2      13
      </pre>

      <p>
	If you would like to print just one of these components, you
	can use one of the <em class="parameter"><code>-l</code></em>
	(lines), <em class="parameter"><code>-w</code></em> (words), or
	<em class="parameter"><code>-c</code></em> (bytes) parameters.
	For instance, adding just the <em class="parameter"><code>-l</code></em> parameter will show the number
	of lines in a file:
      </p>

      <pre class="screen">
$ <span class="command"><strong>wc -l /usr/share/dict/words</strong></span> 
  235882 /usr/share/dict/words
      </pre>

      <p>
	Or, you can print additional fields by adding a parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>wc -lc /usr/share/dict/words</code></strong>
 235882 2493082 /usr/share/dict/words
      </pre>

      <p>
	Please note that, no matter the order in which the options
	were specified, the output order will always be the same
	(lines, words, bytes).
      </p>

      <p>
	Since <em class="parameter"><code>-c</code></em> prints the
	number bytes, this parameter may not represent the number of
	characters that a text holds, because the character set in use
	maybe be wider than one byte. To this end, the <em class="parameter"><code>-m</code></em> parameter has been added which
	prints the number of characters in a text, independent of the
	character set. <em class="parameter"><code>-c</code></em> and
	<em class="parameter"><code>-m</code></em> are substitutes, and
	can never be used at the same time.
      </p>

      <p>
	The statistics that <span class="command"><strong>wc</strong></span> provides are more
	useful than they may seem on the surface. For example, the
	<em class="parameter"><code>-l</code></em> parameter is often
	used as a counter for the output of a command. This is
	convenient, because many commands seperate logical units by a
	newline.  Suppose that you would like to count the number of
	files in your home directory having a filename ending with
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.txt</code></html:span>. You could do this by combining
	<span class="command"><strong>find</strong></span> to find the relevant files and
	<span class="command"><strong>wc</strong></span> to count the number of occurences:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>find ~ -name '*.txt' -type f | wc -l</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-simple-tr"></a>9.1.3. Manipulating characters</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>tr</strong></span> command can be used to do common
	character operations, like swapping characters, deleting
	characters, and squeezing character sequences. Depending on
	the operation, one or two sets of characters should be
	specified. Besides normal characters, there are some special
	character sequences that can be used:
      </p>

      <div class="variablelist"><dl class="variablelist">
<dt><span class="term">\character</span></dt>
<dd>
	    <p>
	      This notation is used to specify characters that need
	      escaping, most notably <span class="emphasis"><em>\n</em></span>
	      (newline), <span class="emphasis"><em>\t</em></span> (horizontal tab), and
	      <span class="emphasis"><em>\\</em></span> (backslash).
	    </p>
	  </dd>
<dt><span class="term">character1-character2</span></dt>
<dd>
	    <p>
	      Implicitly insert all characters from
	      <span class="emphasis"><em>character1</em></span> to
	      <span class="emphasis"><em>character2</em></span>. This notation should be
	      used with care, because it does not always give the
	      expected result. For instance, the sequence
	      <span class="emphasis"><em>a-d</em></span> may yield
	      <span class="emphasis"><em>abcd</em></span> for the POSIX locale (language
	      setting), but this may not be true for other locales.
	      
	    </p>
	  </dd>
<dt><span class="term">[:class:]</span></dt>
<dd>
	    <p>
	      Match a predefined class of characters. All possible
	      classes are shown in <a class="xref" href="#chap-textproc-simple-tr-charclasses" title="Table 9.1. tr character classes">Table 9.1, “tr character classes”</a>.
	    </p>
	  </dd>
<dt><span class="term">[character*]</span></dt>
<dd>
	    <p>
	      Repeat <span class="emphasis"><em>character</em></span> until the second
	      set is as long as the first set of characters. This
	      notation can only be used in the second set.
	    </p>
	  </dd>
<dt><span class="term">[character*n]</span></dt>
<dd>
	    <p>
	      Repeat <span class="emphasis"><em>character</em></span>
	      <span class="emphasis"><em>n</em></span> times.
	    </p>
	  </dd>
</dl></div>

      <div class="table">
<a name="chap-textproc-simple-tr-charclasses"></a><p class="title"><b>Table 9.1. tr character classes</b></p>
<div class="table-contents">
	

	<table summary="tr character classes" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Class</th>
<th>Meaning</th>
</tr></thead>
<tbody>
<tr>
<td>[:alnum:]</td>
<td>All letters and numbers.</td>
</tr>
<tr>
<td>[:alpha:]</td>
<td>Letters.</td>
</tr>
<tr>
<td>[:blank:]</td>
<td>Horizontal whitespace (e.g. spaces and tabs).</td>
</tr>
<tr>
<td>[:cntrl:]</td>
<td>Control characters.</td>
</tr>
<tr>
<td>[:digit:]</td>
<td>All digits (0-9).</td>
</tr>
<tr>
<td>[:graph:]</td>
<td>All printable characters, except whitespace.</td>
</tr>
<tr>
<td>[:lower:]</td>
<td>Lowercase letters.</td>
</tr>
<tr>
<td>[:print:]</td>
<td>All printable characters, including horizontal
	      whitespace, but excluding vertical whitespace.</td>
</tr>
<tr>
<td>[:punct:]</td>
<td>Punctuation characters.</td>
</tr>
<tr>
<td>[:space:]</td>
<td>All whitespace.</td>
</tr>
<tr>
<td>[:upper:]</td>
<td>Uppercase letters.</td>
</tr>
<tr>
<td>[:xdigit:]</td>
<td>Hexadecimal digits (0-9, a-f).</td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-simple-tr-swapping"></a>9.1.3.1. Swapping characters</h4></div></div></div>
	

	<p>
	  The default operation of <span class="command"><strong>tr</strong></span> is to swap
	  (translate) characters. This means that the
	  <span class="emphasis"><em>n</em></span>-th character in the first set is
	  replaced with the <span class="emphasis"><em>n</em></span>-th character in the
	  second set. For example, you can replace all
	  <span class="emphasis"><em>e</em></span>'s with <span class="emphasis"><em>i</em></span>'s and
	  <span class="emphasis"><em>o</em></span>'s with <span class="emphasis"><em>a</em></span>'s with
	  one <span class="command"><strong>tr</strong></span> operation:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>echo 'Hello world!' | tr 'eo' 'ia'</code></strong>
Hilla warld!
	</pre>

	<p>
	  When the second set is not as large as the first set,
	  the last character in the second set will be repeated.
	  Though, this does not necessarily apply to other UNIX
	  systems. So, if you want to use
	  <span class="command"><strong>tr</strong></span> in a system-independent manner,
	  explicitly define what character should be repeated. For
	  instance
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>echo 'Hello world!' | tr 'eaiou' '[@*]'</code></strong>
H@ll@ w@rld!
	</pre>

	<p>
	  Another particularity is the use of the repetition syntax in
	  the middle of the set. Suppose that set 1 is
	  <span class="emphasis"><em>abcdef</em></span>, and set 2
	  <span class="emphasis"><em>@[-*]!</em></span>. <span class="command"><strong>tr</strong></span> will replace
	  <span class="emphasis"><em>a</em></span> with <span class="emphasis"><em>@</em></span>,
	  <span class="emphasis"><em>b</em></span>, <span class="emphasis"><em>c</em></span>,
	  <span class="emphasis"><em>d</em></span>, and <span class="emphasis"><em>e</em></span> with
	  <span class="emphasis"><em>-</em></span>, and <span class="emphasis"><em>f</em></span> with
	  <span class="emphasis"><em>!</em></span>.
	  Though some other UNIX systems follow replace
	  <span class="emphasis"><em>a</em></span> with
	  <span class="emphasis"><em>@</em></span>, and the rest of the set characters
	  with <span class="emphasis"><em>-</em></span>. So, a more correct notation
	  would be the more explicit <span class="emphasis"><em>@[-*4]!</em></span>,
	  which gives the same results on virtually all UNIX systems:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>echo 'abcdef' | tr 'abcdef' '@[-*4]!'</code></strong>
@----!
	</pre>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-simple-tr-squeezing"></a>9.1.3.2. Squeezing character sequences</h4></div></div></div>
	

	<p>
	  When the <em class="parameter"><code>-s</code></em> parameter
	  is used, <span class="command"><strong>tr</strong></span> will squeeze all characters
	  that are in the second set. This means that a sequence of the
	  same characters will be reduced to one character. Let's
	  squeeze the character "<span class="emphasis"><em>e</em></span>":
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>echo "Let's squeeze this." | tr -s 'e'</code></strong>
Let's squeze this.
	</pre>

	<p>
	  We can combine this with translation to show a useful
	  example of <span class="command"><strong>tr</strong></span> in action. Suppose that we
	  would like to mark all vowels with the
	  <span class="emphasis"><em>at</em></span> sign (<span class="emphasis"><em>@</em></span>), with
	  consecutive vowels represented by one
	  <span class="emphasis"><em>at</em></span> sign. This can easily be done by
	  piping two <span class="command"><strong>tr</strong></span> commands:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>echo "eenie meenie minie moe" | tr 'aeiou' '[@*]' | tr -s '@'</code></strong>
@n@ m@n@ m@n@ m@
	</pre>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-simple-tr-deleting"></a>9.1.3.3. Deleting characters</h4></div></div></div>
	

	<p>
	  Finally, <span class="command"><strong>tr</strong></span> can be used to delete
	  characters. If the <em class="parameter"><code>-d</code></em>
	  parameter is used, all characters from the first set are
	  removed:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>echo 'Hello world!' | tr -d 'lr'</code></strong>
Heo wod!
	</pre>
      </div>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-cutpaste"></a>9.1.4. Cutting and pasting text columns</h3></div></div></div>
      

      <p>
	The <span class="command"><strong>cut</strong></span> command is provided by UNIX systems
	to <span class="quote">“<span class="quote">cut</span>”</span> one or more columns from a file or
	stream, printing it to the standard output. It is often useful
	to selectively pick some information from a
	text. <span class="command"><strong>cut</strong></span> provides three approaches to
	cutting information from files:
      </p>

      <div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
	  <p>
	    By byte.
	  </p>
	</li>
<li class="listitem">
	  <p>
	    By character, which is not the same as cutting by byte on
	    systems that use a character set that is wider than eight
	    bits.
	  </p>
	</li>
<li class="listitem">
	  <p>
	    By field, that is delimited by a character.
	  </p>
	</li>
</ol></div>

      <p>
	In all three approaches, you can specify the element to choose
	by its number starting at <span class="emphasis"><em>1</em></span>. You can
	specify a range by using a dash (<span class="emphasis"><em>-</em></span>). So,
	<span class="emphasis"><em>M-N</em></span> means the Mth to the Nth
	element. Leaving M out (<span class="emphasis"><em>-N</em></span>) selects all
	elements from the first element to the Nth element. Leaving N
	out (<span class="emphasis"><em>M-</em></span>) selects the Mth element to the
	last element. Multiple elements or ranges can be combined by
	separating them by commas (<span class="emphasis"><em>,</em></span>). So, for
	instance, <span class="emphasis"><em>1,3-</em></span> selects the first element
	and the third to the last element.
      </p>

      <p>
	Data can be cut by field with the <em class="parameter"><code>-f fields</code></em> parameter. By default,
	the horizontal tab is used a separator. Let's have a look at
	<span class="command"><strong>cut</strong></span> in action with a tiny Dutch to English
	dictionary:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat dictionary</code></strong>
appel   apple
banaan  banana
peer    pear
      </pre>

      <p>
	We can get all English words by selecting the second field:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cut -f 2 dictionary</code></strong>
apple
banana
pear
      </pre>

      <p>
	That was quite easy. Now let's do the same thing with a file
	that has a colon as the field separator. We can easily try
	this by converting the dictionary with the
	<span class="command"><strong>tr</strong></span> command that we have seen earlier,
	replacing all tabs with colons:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>tr '\t' ':' &lt; dictionary &gt; dictionary-new</code></strong>
$ <strong class="userinput"><code>cat dictionary-new</code></strong>
appel:apple
banaan:banana
peer:pear
      </pre>

      <p>
	If we use the same command as in the previous example, we do
	not get the correct output:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cut -f 2 dictionary-new</code></strong>
appel:apple
banaan:banana
peer:pear
      </pre>

      <p>
	What happens here is that the delimiter could not be found.
	If a line does not contain the delimiter that is being used,
	the default behavior of <span class="command"><strong>cut</strong></span> is to print the
	complete line. You can prevent this with the <em class="parameter"><code>-s</code></em> parameter.
      </p>

      <p>
	To use a different delimiter than the horizontal tab, add the
	<em class="parameter"><code>-d delimter_char</code></em>
	parameter to set the delimiting character. So, in this case of
	our <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">dictionary-new</code></html:span> file, we will ask
	<span class="command"><strong>cut</strong></span> to use the colon as a delimiter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cut -d ':' -f 2 dictionary-new</code></strong>
apple
banana
pear
      </pre>

      <p>
	If a field that was specified does not exist in a line, that
	particular field is not printed.
      </p>

      <p>
	The <em class="parameter"><code>-b bytes</code></em> and
	<em class="parameter"><code>-c characters</code></em>
	respectively select bytes and characters from the text. On
	older systems a character used to be a byte wide. But newer
	systems can provide character sets that are wider than one
	byte. So, if you want to be sure to grab complete characters,
	use the <em class="parameter"><code>-c</code></em> parameter.
	An entertaining example of seeing the <em class="parameter"><code>-c</code></em> parameter in action is to find
	the ten most common sets of the first four characters of a
	word. Most UNIX systems provide a list of words that are
	separated by a new line. bsd-games package in Slackware Linux
	contains /usr/share/dict/words with such a list.
	We can use <span class="command"><strong>cut</strong></span> to
	get the first four characters of the words in the word list,
	add <em class="parameter"><code>uniq</code></em>  to count identical four character sequences, and
	use <span class="command"><strong>sort</strong></span> to sort them reverse-numerically
	(<span class="command"><strong>sort</strong></span> is described in <a class="xref" href="#chap-textproc-simple-sort" title="9.1.5. Sorting text">Section 9.1.5, “Sorting text”</a>). Finally, we will use
	<span class="command"><strong>head</strong></span> to get the ten most frequent sequences:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cut -c 1-4 /usr/share/dict/words | uniq -c | sort -nr | head</code></strong>
    254 inte
    206 comp
    169 cons
    161 cont
    150 over
    125 tran
    111 comm
    100 disc
     99 conf
     96 reco
      </pre>

      <p>
	Having concluded with that nice piece of UNIX commands in
	action, we will move on to the <span class="command"><strong>paste</strong></span>
	command, which combines files in columns in a single text
	stream.
      </p>

      <p>
	Usage of <span class="command"><strong>paste</strong></span> is very simple, it will
	combine all files given as an argument, separated by a tab.
	With the list of English and Dutch words, we can generate
	a tiny dictionary:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>paste dictionary-en dictionary-nl</code></strong>
apple   appel
banana  banaan
pear    peer
      </pre>

      <p>
	You can also combine more than two files:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>paste dictionary-en dictionary-nl dictionary-de</code></strong> 
apple   appel   Apfel
banana  banaan  Banane
pear    peer    Birne
      </pre>

      <p>
	If one of the files is longer, the column order is maintained,
	and empty entries are used to fill up the entries of the
	shorter files.
      </p>

      <p>
	You can use another delimiter by adding the <em class="parameter"><code>-d delimiter</code></em> parameter. For
	example, we can make a colon-separated dictionary:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>paste -d ':' dictionary-en dictionary-nl</code></strong>
apple:appel
banana:banaan
pear:peer
      </pre>

      <p>
	Normally, <span class="command"><strong>paste</strong></span> combines files as different
	columns. You can also let <span class="command"><strong>paste</strong></span> use the
	lines of each file as columns, and put the columns of each
	file on a separate line. This is done with the <em class="parameter"><code>-s</code></em> parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>paste -s dictionary-en dictionary-nl dictionary-de</code></strong>
apple   banana  pear
appel   banaan  peer
Apfel   Banane  Birne
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-simple-sort"></a>9.1.5. Sorting text</h3></div></div></div>
      

      <p>
	UNIX offers the <span class="command"><strong>sort</strong></span> command to sort
	text. <span class="command"><strong>sort</strong></span> can also check whether a file is
	in sorted order, and merge two sorted
	files. <span class="command"><strong>sort</strong></span> can sort in dictionary and
	numerical orders. The default sort order is the dictionary
	order. This means that text lines are compared character by
	character, sorted as specified in the current collating
	sequence (which is specified through the LC_COLLATE
	environment variable). This has a catch when you are sorting
	numbers, for instance, if you have the numbers 1 to 10 on
	different lines, the sequence will be 1, 10, 2, 3, etc.  This
	is caused by the per-character interpretation of the
	dictionary sort. If you want to sort lines by number, use the
	numerical sort.
      </p>

      <p>
	If no additional parameters are specified,
	<span class="command"><strong>sort</strong></span> sorts the input lines in dictionary
	order. For instance:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat &lt;&lt; EOF | sort</code></strong>
orange
apple
banana
EOF
apple
banana
orange
      </pre>

      <p>
	As you can see, the input is correctly ordered. Sometimes
	there are two identical lines. You can merge identical lines
	by adding the <em class="parameter"><code>-u</code></em>
	parameter. The two samples listed below illustrate this.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat &lt;&lt; EOF | sort</code></strong>
orange
apple
banana
banana
EOF
apple
banana
banana
orange
$ <strong class="userinput"><code>cat &lt;&lt; EOF | sort -u</code></strong>
orange
apple
banana
banana
EOF
apple
banana
orange
      </pre>

      <p>
	There are some additional parameters that can be helpful to
	modify the results a bit:
      </p>

      <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	  <p>
	    The <em class="parameter"><code>-f</code></em> parameter
	    makes the sort case-insensitive.
	  </p>
	</li>
<li class="listitem">
	  <p>
	    If <em class="parameter"><code>-d</code></em> is added,
	    only blanks and alphanumeric characters are used to
	    determine the order.
	  </p>
	</li>
<li class="listitem">
	  <p>
	    The <em class="parameter"><code>-i</code></em> parameter
	    makes <span class="command"><strong>sort</strong></span> ignore non-printable
	    characters.
	  </p>
	</li>
</ul></div>


      <p>
	You can sort files numerically by adding the <em class="parameter"><code>-n</code></em> parameter. This parameter stops
	reading the input line when a non-numeric character was found.
	The leading minus sign, decimal point, thousands separator,
	radix character (that separates an exponential from a normal
	number), and blanks can be used as a part of a number. These
	characters are interpreted where applicable.
      </p>

      <p>
	The following example shows numerical sort in action, by
	piping the output of <span class="command"><strong>du</strong></span> to
	<span class="command"><strong>sort</strong></span>. This works because
	<span class="command"><strong>du</strong></span> specifies the size of each file as the
	first field.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>du -a /bin | sort -n</code></strong>
0       /bin/kernelversion
0       /bin/ksh
0       /bin/lsmod.modutils
0       /bin/lspci
0       /bin/mt
0       /bin/netcat
[...]
      </pre>

      <p>
	In this case, the output is probably not useful if you want to
	read the output in a paginator, because the smallest files are
	listed first. This is where the <em class="parameter"><code>-r</code></em> parameter becomes handy. This
	reverses the sort order.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>du -a /bin | sort -nr</code></strong>
4692    /bin
1036    /bin/ksh93
668     /bin/bash
416     /bin/busybox
236     /bin/tar
156     /bin/ip
[...]
      </pre>

      <p>
	The <em class="parameter"><code>-r</code></em> parameter also
	works with dictionary sorts.
      </p>

      <p>
	Quite often, files use a layout with multiple columns, and you
	may want to sort a file by a different column than the first
	column. For instance, consider the following score file named
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">score.txt</code></html:span>:
      </p>

      <pre class="programlisting">
John:US:4
Herman:NL:3
Klaus:DE:5
Heinz:DE:3
      </pre>
     
    <p>
      Suppose that we would like to sort the entries in this file by
      the two-letter country name. <span class="command"><strong>sort</strong></span> allows us
      to sort a file by a column with the <em class="parameter"><code>-k col1[,col2]</code></em> parameter.  Where
      <span class="emphasis"><em>col1</em></span> up to <span class="emphasis"><em>col2</em></span> are
      used as fields for sorting the input. If
      <span class="emphasis"><em>col2</em></span> is not specified, all fields up till
      the end of the line are used. So, if you want to use just one
      column, use <em class="parameter"><code>-k col1,col1</code></em>.
      You can also specify the starting character within a column
      by adding a period (<span class="emphasis"><em>.</em></span>) and a character
      index. For instance, <em class="parameter"><code>-k
      2.3,4.2</code></em> means that the second column starting from
      the third character, the third column, and the fourth column up
      to (and including) the second character.
    </p>

    

    <p>
      There is yet another particularity when it comes to sorting by
      columns: by default, <span class="command"><strong>sort</strong></span> uses a blank as the
      column separator. If you use a different separator character,
      you will have to use the <em class="parameter"><code>-t char</code></em>
      parameter, that is used to specify the field separator.
    </p>

    <p>
      With the <em class="parameter"><code>-t</code></em> and
      <em class="parameter"><code>-k</code></em> parameters combined,
      we can sort the scores file by country code:
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>sort -t ':' -k 2,2 scores.txt</code></strong>
Heinz:DE:3
Klaus:DE:5
Herman:NL:3
John:US:4
    </pre>

    <p>
      So, how can we sort the file by the score? Obviously, we have to
      ask sort to use the third column. But sort uses a dictionary
      sort by default<a href="#ftn.idm950899036" class="footnote" name="idm950899036"><sup class="footnote">[6]</sup></a>. You could use the <em class="parameter"><code>-n</code></em>, but <span class="command"><strong>sort</strong></span> also
      allows a more sophisticated approach. You can append the one or
      more of the <span class="emphasis"><em>n</em></span>, <span class="emphasis"><em>r</em></span>,
      <span class="emphasis"><em>f</em></span>, <span class="emphasis"><em>d</em></span>,
      <span class="emphasis"><em>i</em></span>, or <span class="emphasis"><em>b</em></span> to the column
      specifier. These letters represent the <span class="command"><strong>sort</strong></span>
      parameters with the same name. If you add just the starting
      column, append it to that column, otherwise, add it to the
      ending column.
    </p>

    <p>
      The following command sorts the file by score:
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>sort -t ':' -k 3n /home/daniel/scores.txt</code></strong>
Heinz:DE:3
Herman:NL:3
John:US:4
Klaus:DE:5
    </pre>

    <p>
      It is good to follow this approach, rather than using the
      parameter variants, because <span class="command"><strong>sort</strong></span> allows you
      to use more than one <em class="parameter"><code>-k</code></em>
      parameter. And, adding these flags to the column specification,
      will allow you to sort by different columns in different ways.
      For example using <span class="command"><strong>sort</strong></span> with the <em class="parameter"><code>-k 3,3n -k 2,2</code></em> parameters will sort
      all lines numerically by the third column. If some lines have
      identical numbers in the third column, these lines can be sorted
      further with a dictionary sort of the second column.
    </p>

    <p>
      If you want to check whether a file is already sorted, you can
      use the <em class="parameter"><code>-c</code></em> parameter.  If
      the file was in a sorted order, sort will return the value
      <span class="emphasis"><em>0</em></span>, otherwise <span class="emphasis"><em>1</em></span>. We can
      check this by echoing the value of the <span class="emphasis"><em>?</em></span>
      variable, which holds the return value of the last executed
      command.
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>sort -c scores.txt ; echo $?</code></strong>
1
$ <strong class="userinput"><code>sort scores.txt | sort -c ; echo $?</code></strong>
0
    </pre>

    <p>
      The second command shows that this actually works, by piping the
      output of the sort of <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">scores.txt</code></html:span> to
      <span class="command"><strong>sort</strong></span>.
    </p>

    <p>
      Finally, you can merge two sorted files with the <em class="parameter"><code>-m</code></em> parameter, keeping the correct
      sort order. This is faster than concatenating both files, and
      resorting them.
    </p>

    <pre class="screen">
# <strong class="userinput"><code>sort -m scores-sorted.txt scores-sorted2.txt</code></strong>
    </pre>
  </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-simple-diff"></a>9.1.6. Differences between files</h3></div></div></div>
      

      <p>
	Since text streams, and text files are very important in UNIX,
	it is often useful to show the differences between two text
	files. The main utilities for working with file differences
	are <span class="command"><strong>diff</strong></span> and
	<span class="command"><strong>patch</strong></span>. <span class="command"><strong>diff</strong></span> shows the
	differences between files. The output of
	<span class="command"><strong>diff</strong></span> can be processed by
	<span class="command"><strong>patch</strong></span> to apply the changes between two
	files to a file. <span class="quote">“<span class="quote">diffs</span>”</span> are also form the base
	of version/source management systems.  The following sections
	describe <span class="command"><strong>diff</strong></span> and <span class="command"><strong>patch</strong></span>.
	To have some material to work with, the following two C source
	files are used to demonstrate these commands. These files are
	named <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.c</code></html:span> and
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello2.c</code></html:span> respectively.
      </p>

      <pre class="programlisting">

#include &lt;stdio.h&gt;

void usage(char *programName);

int main(int argc, char *argv[]) {
  if (argc == 1) {
    usage(argv[0]);
    return 1;
  }

  printf("Hello %s!\n", argv[1]);

  return 0;
}

void usage(char *programName) {
  printf("Usage: %s name\n", programName);
}

      </pre>

      <pre class="programlisting">
#include &lt;stdio.h&gt;
<span class="bold"><strong>#include &lt;time.h&gt;</strong></span>

void usage(char *programName);

int main(int argc, char *argv[]) {
  if (argc == 1) {
    usage(argv[0]);
    return 1;
  }

  printf("Hello %s!\n", argv[1]);

  <span class="bold"><strong>time_t curTime = time(NULL);</strong></span>
  <span class="bold"><strong>printf("The date is %s\n", asctime(localtime(&amp;curTime)));</strong></span>


  return 0;
}

void usage(char *programName) {
  printf("Usage: %s name\n", programName);
}
      </pre>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-simple-diff-diff"></a>9.1.6.1. Listing differences between files</h4></div></div></div>
	

	<p>
	  Suppose that you received the program
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.c</code></html:span> from a friend, and you modified
	  it to give the user the current date and time. You could
	  just send your friend the updated program. But if a file
	  grows larger, they can become uncomfortable, because the
	  changes are harder to spot. Besides that, your friend may
	  have also received modified program sources from other
	  persons. This is a typical situation where
	  <span class="command"><strong>diff</strong></span> becomes
	  handy. <span class="command"><strong>diff</strong></span> shows the differences between
	  two files. Its most basic syntax is <span class="command"><strong>diff file
	  file2</strong></span>, which shows the differences between
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file</code></html:span> and
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">file2</code></html:span>. Let's try this with the our
	  source files:
	</p>

	<pre class="screen">
$ diff hello.c hello2.c
1a2 <a name="co-diff-append"></a><span><img src="../images/callouts/1.png" alt="1" border="0"></span>
&gt; #include &lt;time.h&gt; <a name="co-diff-incoming"></a><span><img src="../images/callouts/2.png" alt="2" border="0"></span>
12a14,17
&gt;   time_t curTime = time(NULL);
&gt;   printf("The date is %s\n", asctime(localtime(&amp;curTime)));
&gt;
	</pre>

	<p>
	  The additions from <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello2.c</code></html:span> are visible
	  in this output, but the format may look a bit
	  strange. Actually, these are commands that can be
	  interpreted by the <span class="command"><strong>ed</strong></span> line editor. We will
	  look at a more comfortable output format after touching the
	  surface of the default output format.
	</p>

	<p>
	  Two different elements can be distilled from this output:
	</p>

	<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-diff-append"><span><img src="../images/callouts/1.png" alt="1" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      This is an <span class="application">ed</span> command that
	      specified that text should be appended
	      (<code class="literal">a</code>) after line <code class="literal">2</code>.
	    </p>
	  </td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-diff-incoming"><span><img src="../images/callouts/2.png" alt="2" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      This is the actual text to be appended after the second
	      line. The <span class="quote">“<span class="quote"><span class="emphasis"><em>&gt;</em></span></span>”</span> sign
	      is used to mark lines that are added.
	    </p>
	  </td>
</tr>
</table></div>

	<p>
	  The same elements are used to add the second block of text.
	  What about lines that are removed? We can easily see how
	  they are represented by swapping the two parameters to
	  <span class="command"><strong>diff</strong></span>, showing the differences between
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello2.c</code></html:span> and
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.c</code></html:span>:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>diff hello2.c hello.c</code></strong>
2d1 <a name="co-diff-delete"></a><span><img src="../images/callouts/1.png" alt="1" border="0"></span>
&lt; #include &lt;time.h&gt; <a name="co-diff-outgoing"></a><span><img src="../images/callouts/2.png" alt="2" border="0"></span>
14,16d12
&lt;   time_t curTime = time(NULL);
&lt;   printf("The date is %s\n", asctime(localtime(&amp;curTime)));
&lt;
	</pre>

	<p>
	  The following elements can be distinguished:
	</p>

	<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-diff-delete"><span><img src="../images/callouts/1.png" alt="1" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      This is the <span class="application">ed</span> delete command
	      (<code class="literal">d</code>), stating that line 2 should be
	      deleted. The second delete command uses a range (line 14
	      to 17).
	    </p>
	  </td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-diff-outgoing"><span><img src="../images/callouts/2.png" alt="2" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      The text that is going to be removed is preceded by the
	      <span class="quote">“<span class="quote">&lt;</span>”</span> sign.
	    </p>
	  </td>
</tr>
</table></div>

	

	<p>
	  That's enough of the <span class="application">ed</span>-style
	  output. The GNU diff program included in Slackware Linux
	  supports so-called unified diffs. Unified diffs are very
	  readable, and provide context by
	  default. <span class="command"><strong>diff</strong></span> can provide unified output
	  with the <em class="parameter"><code>-u</code></em> flag:
	</p>

	<pre class="screen">
$ diff -u hello.c hello2.c
--- hello.c     2006-11-26 20:28:55.000000000 +0100 <a name="co-udiff-origfile"></a><span><img src="../images/callouts/1.png" alt="1" border="0"></span>
+++ hello2.c    2006-11-26 21:27:52.000000000 +0100 <a name="co-udiff-newfile"></a><span><img src="../images/callouts/2.png" alt="2" border="0"></span>
@@ -1,4 +1,5 @@ <a name="co-udiff-lines"></a><span><img src="../images/callouts/3.png" alt="3" border="0"></span>
 #include &lt;stdio.h&gt; <a name="co-udiff-unmodified"></a><span><img src="../images/callouts/4.png" alt="4" border="0"></span>
+#include &lt;time.h&gt; <a name="co-udiff-add"></a><span><img src="../images/callouts/5.png" alt="5" border="0"></span>

 void usage(char *programName);

@@ -10,6 +11,9 @@

   printf("Hello %s!\n", argv[1]);

+  time_t curTime = time(NULL);
+  printf("The date is %s\n", asctime(localtime(&amp;curTime)));
+
   return 0;
 }

	</pre>

	<p>
	  The following elements can be found in the output
	</p>

	<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-udiff-origfile"><span><img src="../images/callouts/1.png" alt="1" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      The name of the original file, and the timestamp of the
	      last modification time.
	    </p>
	  </td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-udiff-newfile"><span><img src="../images/callouts/2.png" alt="2" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      The name of the changed file, and the timestamp of the
	      last modification time.
	    </p>
	  </td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-udiff-lines"><span><img src="../images/callouts/3.png" alt="3" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      This pair of numbers show the location and size of the
	      chunk that the text below affects in the original file
	      and the modified file. So, in this case the numbers mean
	      that in the affected chunk in the original file starts
	      at line 1, and is four lines long. In the modified file
	      the affected chunk starts at line 1, and is five lines
	      long. Different chunks in diff output are started by
	      this header.
	    </p>
	  </td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-udiff-unmodified"><span><img src="../images/callouts/4.png" alt="4" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      A line that is not preceded by a minus
	      (<span class="emphasis"><em>-</em></span>) or plus
	      (<span class="emphasis"><em>+</em></span>) sign is unchanged. Unmodified
	      lines are included because they give contextual
	      information, and to avoid that too many chunks are
	      made. If there are only a few unmodified lines between
	      changes, <span class="command"><strong>diff</strong></span> will choose to make
	      only one chunk, rather than two chunks.
	    </p>
	  </td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-udiff-add"><span><img src="../images/callouts/5.png" alt="5" border="0"></span></a> </p></td>
<td valign="top" align="left">
	    <p>
	      A line that is preceded by a plus sign
	      (<span class="emphasis"><em>+</em></span>) is an addition to the modified
	      file, compared to the original file.
	    </p>
	  </td>
</tr>
</table></div>

	<p>
	  As with the ed-style <span class="command"><strong>diff</strong></span> format, we can
	  see some removals by swapping the file names:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>diff -u hello2.c hello.c</code></strong>

--- hello2.c    2006-11-26 21:27:52.000000000 +0100
+++ hello.c     2006-11-26 20:28:55.000000000 +0100
@@ -1,5 +1,4 @@
 #include &lt;stdio.h&gt;
-#include &lt;time.h&gt;

 void usage(char *programName);

@@ -11,9 +10,6 @@

   printf("Hello %s!\n", argv[1]);

-  time_t curTime = time(NULL);
-  printf("The date is %s\n", asctime(localtime(&amp;curTime)));
-
   return 0;
 }


	</pre>

	<p>
	  As you can see from this output, lines that are removed from
	  the modified file, in contrast to the original file are
	  preceded by the minus (<span class="emphasis"><em>-</em></span>) sign.
	</p>

	<p>
	  When you are working on larger sets of files, it's often
	  useful to compare whole directories. For instance, if you
	  have the original version of a program source in a directory
	  named <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.orig</code></html:span>, and the modified
	  version in a directory named <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello</code></html:span>, you
	  can use the <em class="parameter"><code>-r</code></em>
	  parameter to recursively compare both directories. For
	  instance:
	</p>

	<pre class="screen">
$ diff -ru hello.orig hello
diff -ru hello.orig/hello.c hello/hello.c

--- hello.orig/hello.c  2006-12-04 17:37:14.000000000 +0100
+++ hello/hello.c       2006-12-04 17:37:48.000000000 +0100
@@ -1,4 +1,5 @@
 #include &lt;stdio.h&gt;
+#include &lt;time.h&gt;

 void usage(char *programName);

@@ -10,6 +11,9 @@

   printf("Hello %s!\n", argv[1]);

+  time_t curTime = time(NULL);
+  printf("The date is %s\n", asctime(localtime(&amp;curTime)));
+
   return 0;
 }


	</pre>

	<p>
	  It should be noted that this will only compare files that
	  are available in both directories. The GNU version of diff,
	  that is used by Slackware Linux provides the
	  <em class="parameter"><code>-N</code></em> parameter. This
	  parameter treats files that exist in only one of both
	  directories as if it were an empty file. So for instance,
	  if we have added a file named <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">Makefile</code></html:span>
	  to the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello</code></html:span> directory, using the
	  <em class="parameter"><code>-N</code></em> parameter will
	  give the following output:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>diff -ruN hello.orig hello</code></strong>

diff -ruN hello.orig/hello.c hello/hello.c
--- hello.orig/hello.c  2006-12-04 17:37:14.000000000 +0100
+++ hello/hello.c       2006-12-04 17:37:48.000000000 +0100
@@ -1,4 +1,5 @@
 #include &lt;stdio.h&gt;
+#include &lt;time.h&gt;

 void usage(char *programName);

@@ -10,6 +11,9 @@

   printf("Hello %s!\n", argv[1]);

+  time_t curTime = time(NULL);
+  printf("The date is %s\n", asctime(localtime(&amp;curTime)));
+
   return 0;
 }

diff -ruN hello.orig/Makefile hello/Makefile
--- hello.orig/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ hello/Makefile      2006-12-04 17:39:44.000000000 +0100
@@ -0,0 +1,2 @@
+hello: hello.c
+       gcc -Wall -o $@ $&lt;

	</pre>

	<p>
	  As you can see the chunk indicator says that the chunk in
	  the original file starts at line 0, and is 0 lines long.
	</p>

	<p>
	  UNIX users often exchange the output of
	  <span class="command"><strong>diff</strong></span>, usually called <span class="quote">“<span class="quote">diffs</span>”</span>
	  or <span class="quote">“<span class="quote">patches</span>”</span>. The next section will show you
	  how you can handle diffs. But you are now able to create
	  them yourself, by redirecting the output of diff to a file.
	  For example:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>diff -u hello.c hello2.c &gt; hello_add_date.diff</code></strong>
	</pre>

	<p>
	  If you have multiple diffs, you can easily combine them to
	  one diff, by concatenating the diffs:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>cat diff1 diff2 diff3 &gt; combined_diff</code></strong>
	</pre>

	<p>
	  But make sure that they were created from the same directory
	  if you want to use the <span class="command"><strong>patch</strong></span> utility that
	  is covered in the next section.
	</p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-simple-diff-patch"></a>9.1.6.2. Modifying files with diff output</h4></div></div></div>
	

	<p>
	  Suppose that somebody would send you the output of
	  <span class="command"><strong>diff</strong></span> for a file that you have created. It
	  would be tedious to manually incorporate all the changes
	  that were made. Fortunately, the <span class="command"><strong>patch</strong></span>
	  can do this for you. <span class="command"><strong>patch</strong></span> accepts diffs
	  on the standard input, and will try to change the original
	  file, according to the differences that are registered in
	  the diff. So, for instance, if we have the
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.c</code></html:span> file, and the patch that we
	  produced previously based on the changes between
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.c</code></html:span> and
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello2.c</code></html:span>, we can patch
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.c</code></html:span> to become equal to its
	  counterpart:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>patch &lt; hello_add_date.diff</code></strong>
patching file hello.c
	</pre>

	<p>
	  If you have <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello2.c</code></html:span>, you can check
	  whether the files are identical now:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>diff -u hello.c hello2.c</code></strong>
	</pre>

	<p>
	  There is no output, so this is the case. One of the nice
	  features of <span class="command"><strong>patch</strong></span> is that it can revert
	  the changes made through a diff, by using the <em class="parameter"><code>-R</code></em> parameter:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>patch -R &lt; hello_add_date.diff</code></strong>
	</pre>

	<p>
	  In these examples, the original file is patched. Sometimes
	  you may want to want to apply the patch to a file with a
	  different name. You can do this by providing the name of
	  a file as the last argument:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>patch helloworld.c &lt; hello_add_date.diff</code></strong>
patching file helloworld.c
	</pre>

	<p>
	  You can also use <span class="command"><strong>patch</strong></span> with diffs that
	  were generated with the <em class="parameter"><code>-r</code></em> parameter, but you have to
	  take a bit of care. Suppose that the header of a particular
	  file in the diff is as follows:
	</p>

	<div class="literallayout"><p><br>
--------------------------<br>
|diff -ruN hello.orig/hello.c hello/hello.c<br>
|--- hello.orig/hello.c 2006-12-04 17:37:14.000000000 +0100<br>
|+++ hello/hello.c      2006-12-04 17:37:48.000000000 +0100<br>
--------------------------<br>
	</p></div>

	<p>
	  If you process this diff with <span class="command"><strong>patch</strong></span>, it
	  will attempt to change <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.c</code></html:span>. So, the
	  directory that holds this file has to be the active
	  directory. You can use the full pathname with the <em class="parameter"><code>-p n</code></em>, where
	  <span class="emphasis"><em>n</em></span> is the number of pathname components
	  that should be stripped. A value of <span class="emphasis"><em>0</em></span>
	  will use the path as it is specified in the patch,
	  <span class="emphasis"><em>1</em></span> will strip the first pathname
	  component, etc. In this example, stripping the first
	  component will result in patching of
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hello.c</code></html:span>. According to the Single UNIX
	  Specification version 3 standard, the path that is preceded
	  by <span class="emphasis"><em>---</em></span> should be used to construct the
	  file that should be patched. The GNU version of patch does
	  not follow the standard here. So, it is best to strip off to
	  the point where both directory names are equal (this is
	  usually the top directory of the tree being changed). In
	  most cases where relative paths are used this can be done
	  by using <span class="emphasis"><em>-p 1</em></span>. For instance:
	</p>

	

	<pre class="screen">
$ <strong class="userinput"><code>cd hello.orig</code></strong>
$ <strong class="userinput"><code>patch -p 1 &lt; ../hello.diff</code></strong>
	</pre>

	<p>
	  Or, you can use the <em class="parameter"><code>-d</code></em> parameter to specify in which
	  directory the change has to be applied:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>patch -p 1 -d hello.orig &lt; hello.diff</code></strong>
patching file hello.c
patching file Makefile
	</pre>

	<p>
	  If you want to keep a backup when you are changing a file,
	  you can use the <em class="parameter"><code>-b</code></em>
	  parameter of <span class="command"><strong>patch</strong></span>. This will make a copy
	  of every affected file named
	  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">filename.orig</code></html:span>, before actually changing
	  the file:
	</p>

	<pre class="screen">
$ <strong class="userinput"><code>patch -b &lt; hello_add_date.diff</code></strong>
$ <strong class="userinput"><code>ls -l hello.c*</code></strong>
-rw-r--r-- 1 daniel daniel 382 2006-12-04 21:41 hello.c
-rw-r--r-- 1 daniel daniel 272 2006-12-04 21:12 hello.c.orig
	</pre>

	<p>
	  Sometimes a file can not be patched. For instance, if it has
	  already been patched, it has changed too much to apply the
	  patch cleanly, or if the file does not exist at all. In this
	  case, the chunks that could not be saved are stored in a
	  file with the name <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">filename.rej</code></html:span>, where
	  <span class="emphasis"><em>filename</em></span> is the file that
	  <span class="command"><strong>patch</strong></span> tried to modify.
	</p>
      </div>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-textproc-regexps"></a>9.2. Regular expressions</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-regexps-intro"></a>9.2.1. Introduction</h3></div></div></div>
      

      <p> In daily life, you will often want to manipulate some text that
      matches to a certain pattern, rather than a literal string. Many
      UNIX utilities implement a language for matching text patterns,
      <span class="emphasis"><em>regular expressions</em></span> (regexps). Over time
      the regular expression language has grown, there are now
      basically three regular expression syntaxes: </p>

      <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          <p> Traditional UNIX regular expressions. </p>
        </li>
<li class="listitem">
          <p> POSIX extended regular expressions. </p>
        </li>
<li class="listitem">
          <p> Perl-compatible regular expressions (PCRE). </p>
        </li>
</ul></div>

      <p>
	POSIX regexps are mostly a superset of traditional UNIX
	regexps, and PCREs a superset of POSIX regexps. The syntax
	that an application supports differs per application, but
	almost all applications support at least POSIX
	regexps.
      </p>

      <p>
	Each syntactical unit in a regexp expresses one of the
	following things:
      </p>

      <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          <p>
            <span class="bold"><strong>A character</strong></span>: this is the
            basis of every regular expression, a character or a set of
            characters to be matched. For instance, the letter
            <span class="emphasis"><em>p</em></span> or the sign
            <span class="emphasis"><em>,</em></span>. </p>
        </li>
<li class="listitem">
          <p>
            <span class="bold"><strong>Quantification</strong></span>: a
            quantifier specifies how many times the preceding
            character or set of characters should be matched. </p>
        </li>
<li class="listitem">
          <p>
            <span class="bold"><strong>Alternation</strong></span>: alternation
            is used to match <span class="quote">“<span class="quote">a or b</span>”</span> in which
            <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> can be a
            character or a regexp. </p>
        </li>
<li class="listitem">
          <p>
            <span class="bold"><strong>Grouping</strong></span>: this is used to
            group subexpressions, so that quantification or
            alternation can be applied to the group. </p>
        </li>
</ul></div>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-regexps-traditional"></a>9.2.2. Traditional UNIX regexps</h3></div></div></div>
      

      <p>
	This section describes traditional UNIX regexps. Because of a
	lack of standardisation, the exact syntax may differ a bit per
	utility. Usually, the manual page of a command provides more
	detailed information about the supported basic or traditional
	regular expressions. It is a good idea to learn traditional
	regexps, but to use POSIX regexps for your own
	scripts.
      </p>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-regexps-traditional-characters"></a>9.2.2.1. Matching characters</h4></div></div></div>
        

        <p>
	  Characters are matched by themselves. If a specific
	  character is used as a syntactic character for regexps, you
	  can match that character by adding a backslash. For
	  instance, <span class="emphasis"><em>\+</em></span> matches the plus
	  character. </p>

        <p>
	  A period (<span class="emphasis"><em>.</em></span>) matches any character, for
	  instance, the regexp <span class="emphasis"><em>b.g</em></span> matches
	  <span class="emphasis"><em>bag</em></span>, <span class="emphasis"><em>big</em></span>, and
	  <span class="emphasis"><em>blg</em></span>, but not
	  <span class="emphasis"><em>bit</em></span>. </p>

        <p>
	  The period character, often provides too much freedom. You
	  can use square brackets (<span class="emphasis"><em>[]</em></span>) to specify
	  characters which can be matched. For instance, the regexp
	  <span class="emphasis"><em>b[aei]g</em></span> matches
	  <span class="emphasis"><em>bag</em></span>, <span class="emphasis"><em>beg</em></span>, and
	  <span class="emphasis"><em>big</em></span>, but nothing else. You can also
	  match any character but the characters in a set by using the
	  square brackets, and using the caret
	  (<span class="emphasis"><em>^</em></span>) as the first character. For
	  instance, <span class="emphasis"><em>b[^aei]g</em></span> matches any three
	  character string that starts with <span class="emphasis"><em>b</em></span> and
	  ends with <span class="emphasis"><em>g</em></span>, with the exception of
	  <span class="emphasis"><em>bag</em></span>, <span class="emphasis"><em>beg</em></span>, and
	  <span class="emphasis"><em>big</em></span>. It is also possible to match a
	  range of characters with a dash
	  (<span class="emphasis"><em>-</em></span>). For example,
	  <span class="emphasis"><em>a[0-9]</em></span> matches a followed by a single
	  number character. </p>

        <p>
	  Two special characters, the caret (<span class="emphasis"><em>^</em></span>)
	  and the dollar sign (<span class="emphasis"><em>$</em></span>), respectively
	  match the start and end of a line. This is very handy for
	  parsing files. For instance, you can match all lines that
	  start with a hash (<span class="emphasis"><em>#</em></span>) with the regexp
	  <span class="emphasis"><em>^#</em></span>. </p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-regexps-traditional-quantification"></a>9.2.2.2. Quantification</h4></div></div></div>
        

        <p>
	  The simplest quantification sign that traditional regular
	  expressions support is the (Kleene) star
	  (<span class="emphasis"><em>*</em></span>). This matches zero or arbitrary
	  instances of the preceding character. For instance,
	  <span class="emphasis"><em>ba*</em></span> matches <span class="emphasis"><em>b</em></span>,
	  <span class="emphasis"><em>ba</em></span><span class="emphasis"><em>baa</em></span>, etc. You
	  should be aware that a single character folowed by a star
	  without any context matches every string, because
	  <span class="emphasis"><em>c*</em></span> also matches a string that has zero
	  <span class="emphasis"><em>c</em></span> characters. </p>

        <p>
	  More specific repetitions can be specified with
	  backslash-escaped curly braces.
	  <span class="emphasis"><em>\{x,y\}</em></span> matches the preceding character
	  at least <span class="emphasis"><em>x</em></span> times, but not more than
	  <span class="emphasis"><em>y</em></span> times. So,
	  <span class="emphasis"><em>ba\{1,3\}</em></span> matches
	  <span class="emphasis"><em>ba</em></span>, <span class="emphasis"><em>baa</em></span>, and
	  <span class="emphasis"><em>baaa</em></span>. </p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-regexps-traditional-grouping"></a>9.2.2.3. Grouping</h4></div></div></div>
        

        <p>
	  Backslash-escaped parentheses group various characters
	  together, so that you can apply quantification or
	  alternation to a group of characters. For instance,
	  <span class="emphasis"><em>\(ab\)\{1,3\}</em></span> matches
	  <span class="emphasis"><em>ab</em></span>, <span class="emphasis"><em>abab</em></span>, and
	  <span class="emphasis"><em>ababab</em></span>. </p>
      </div>

      <div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-regexps-traditional-alternation"></a>9.2.2.4. Alternation</h4></div></div></div>
        

        <p>
	  A backslash-escaped pipe vertical bar
	  (<span class="emphasis"><em>\|</em></span>) allows you to match either of two
	  expressions. This is not useful for single characters,
	  because <span class="emphasis"><em>a\|b</em></span> is equivalent to
	  <span class="emphasis"><em>[ab]</em></span>, but it is very useful in
	  conjunction with grouping. Suppose that you would like an
	  expression that matches <span class="emphasis"><em>apple</em></span> and
	  <span class="emphasis"><em>pear</em></span>, but nothing else. This can be
	  done easily with the vertical bar:
	  <span class="emphasis"><em>(apple)|(pear)</em></span>. </p>
      </div>
    </div>

      <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-regexps-posix"></a>9.2.3. POSIX extended regular expressions</h3></div></div></div>
	

	<p>
	  POSIX regular expressions build upon traditional regular
	  expressions, adding some other useful primitives. Another
	  comforting difference is that grouping parenthesises,
	  quantification accolades, and the alternation sign
	  (<span class="emphasis"><em>|</em></span>) are not backslash-escaped.  If they
	  are escaped, they will match the literal characters instead,
	  thus resulting in the opposite behavior of traditional
	  regular expressions. Most people find POSIX extended regular
	  expressions much more comfortable, making them more widely
	  used.
	</p>

	<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-regexps-posix-characters"></a>9.2.3.1. Matching characters</h4></div></div></div>
	  

	  <p>
	    Normal character matching has not changed compared to the
	    traditional regular expressions described in <a class="xref" href="#chap-textproc-regexps-traditional-characters" title="9.2.2.1. Matching characters">Section 9.2.2.1, “Matching characters”</a>
	  </p>
	</div>

	<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-regexps-posix-quantification"></a>9.2.3.2. Quantification</h4></div></div></div>
	  

	  <p>
	    Besides the Kleene star (<span class="emphasis"><em>*</em></span>), that
	    matches the preceding character or group zero or more
	    times, POSIX extended regular expressions add two new
	    simple quantification primitives. The plus sign
	    (<span class="emphasis"><em>+</em></span>) matches the preceding character
	    or group one or more times. For example,
	    <span class="emphasis"><em>a+</em></span>, matches <span class="emphasis"><em>a</em></span>
	    (or any string with more consecutive
	    <span class="emphasis"><em>a</em></span>'s), but does not match zero
	    <span class="emphasis"><em>a</em></span>'s. The questions mark character
	    (<span class="emphasis"><em>?</em></span>) matches the preceding character
	    zero or one time. So, <span class="emphasis"><em>ba?d</em></span> matches
	    <span class="emphasis"><em>bd</em></span> and <span class="emphasis"><em>bad</em></span>, but
	    not <span class="emphasis"><em>baad</em></span> or <span class="emphasis"><em>bed</em></span>.
	  </p>

	  <p>
	    Curly braces are used for repetition, like traditional
	    regular expressions. Though the backslash should be
	    omitted. To match <span class="emphasis"><em>ba</em></span> and
	    <span class="emphasis"><em>baa</em></span>, one should use
	    <span class="emphasis"><em>ba{1,2}</em></span> rather than
	    <span class="emphasis"><em>ba\{1,2\}</em></span>.
	  </p>
	</div>

	<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-regexps-posix-grouping"></a>9.2.3.3. Grouping</h4></div></div></div>
	  

	  <p>
	    Grouping is done in the same manner as traditional regular
	    expressions, leaving out the escape-backslashes before the
	    parenthesises. For example, <span class="emphasis"><em>(ab){1,3}</em></span>
	    matches <span class="emphasis"><em>ab</em></span>,
	    <span class="emphasis"><em>abab</em></span>, and
	    <span class="emphasis"><em>ababab</em></span>.
	  </p>
	</div>

	<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="chap-textproc-regexps-posix-alternation"></a>9.2.3.4. Alternation</h4></div></div></div>
	  

	  <p>
	    Alternation is done in the same manner as with traditional
	    regular expressions, leaving out the escape-backslashes
	    before the vertical bar. So,
	    <span class="emphasis"><em>(apple)|(pear)</em></span> matches
	    <span class="emphasis"><em>apple</em></span> and <span class="emphasis"><em>pear</em></span>.
	  </p>
	</div>
      </div>

      

  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-textproc-grep"></a>9.3. grep</h2></div></div></div>
    

    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-grep-basic"></a>9.3.1. Basic grep usage</h3></div></div></div>
      

      <p>
	We have now arrived at one of the most important utilties of
	the UNIX System, and the first occasion to try and use regular
	expressions. The <span class="command"><strong>grep</strong></span> command is used to
	search a text stream or a file for a pattern. This pattern is
	a regular expression, and can either be a basic regular
	expression or a POSIX extended regular expression (when the
	<em class="parameter"><code>-E</code></em> parameter is
	used). By default, <span class="command"><strong>grep</strong></span> will write the
	lines that were matched to the standard output. In the most
	basic syntax, you can specify a regular expression as an
	argument, and <span class="command"><strong>grep</strong></span> will search matches in
	the text from the standard input. This is a nice manner to
	practice a bit with regular expressions.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep '^\(ab\)\{2,3\}$'</code></strong>
<strong class="userinput"><code>ab</code></strong>
<strong class="userinput"><code>abab</code></strong>
abab
<strong class="userinput"><code>ababab</code></strong>
ababab
<strong class="userinput"><code>abababab</code></strong>
      </pre>

      <p>
	The example listed above shows a basic regular expression in
	action, that matches a line solely consisting of two or three
	times the <span class="emphasis"><em>ab</em></span> string. You can do the same
	thing with POSIX extended regular expressions, by adding the
	<em class="parameter"><code>-E</code></em> (for extended)
	parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep -E '^(ab){2,3}$'</code></strong>
<strong class="userinput"><code>ab</code></strong>
<strong class="userinput"><code>abab</code></strong>
abab
<strong class="userinput"><code>ababab</code></strong>
ababab
<strong class="userinput"><code>abababab</code></strong>
      </pre>

      <p>
	Since the default behavior of <span class="command"><strong>grep</strong></span> is to
	read from the standard input, you can add it to a pipeline to
	get the interesting parts of the output of the preceding
	commands in the pipeline. For instance, if you would like to
	search for the string <span class="emphasis"><em>2006</em></span> in the third
	column in a file, you could combine the <span class="command"><strong>cut</strong></span>
	and <span class="command"><strong>grep</strong></span> command:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cut -f 3 | grep '2006'</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-grep-files"></a>9.3.2. grepping files</h3></div></div></div>
      

      <p>
	Naturally, <span class="command"><strong>grep</strong></span> can also directly read a
	file, rather than the standard input. As usual, this is done
	by adding the files to be read as the last arguments. The
	following example will print all lines from the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/passwd</code></html:span> file that start with the
	string <span class="emphasis"><em>daniel:</em></span>.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep "^daniel" /etc/passwd</code></strong>
daniel:*:1001:1001:Daniel de Kok:/home/daniel:/bin/sh
      </pre>

      

      <p>
        With the <em class="parameter"><code>-r</code></em> option,
	<span class="command"><strong>grep</strong></span> will recursively traverse a directory
	structure, trying to find matches in each file that was encountered
	during the traversal.
	Though, it is better to combine <span class="command"><strong>grep</strong></span> with
	<span class="command"><strong>find</strong></span> and the <span class="emphasis"><em>-exec</em></span>
	operand in scripts that have to be portable.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep -r 'somepattern' somedir</code></strong>
      </pre>

      <p>
	is the non-portable functional equivalent of
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>find /somedir -type f -exec grep 'somepattern' {} \; -print</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-grep-pattern"></a>9.3.3. Pattern behavior</h3></div></div></div>
      

      <p>
	<span class="command"><strong>grep</strong></span> can also print all lines that do not
	match the pattern that was used.  This is done by adding the
	<em class="parameter"><code>-v</code></em> parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep -Ev '^(ab){2,3}$'</code></strong>
<strong class="userinput"><code>ab</code></strong>
ab
<strong class="userinput"><code>abab</code></strong>
<strong class="userinput"><code>ababab</code></strong>
<strong class="userinput"><code>abababab</code></strong>
abababab
      </pre>

      <p>
	If you want to use the pattern in a case-insensitive manner,
	you can add the <em class="parameter"><code>-i</code></em>
	parameter. For example:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep -i "a"</code></strong>
<strong class="userinput"><code>a</code></strong>
a
<strong class="userinput"><code>A</code></strong>
A
      </pre>

      <p>
	You can also match a string literally with the <em class="parameter"><code>-F</code></em> parameter:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep -F 'aa*'</code></strong>
<strong class="userinput"><code>a</code></strong>
<strong class="userinput"><code>aa*</code></strong>
aa*
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-textproc-grep-multiplepatterns"></a>9.3.4. Using multiple patterns</h3></div></div></div>
      

      <p>
	As we have seen, you can use the alternation character
	(<span class="emphasis"><em>|</em></span>) to match either of two or more
	subpatterns. If two patterns that you would like to match
	differ a lot, it is often more comfortable to make two
	separate patterns. <span class="command"><strong>grep</strong></span> allows you to use
	more than one pattern by separating patterns with a newline
	character. So, for example, if you would like to print lines
	that match either the <span class="emphasis"><em>a</em></span> or
	<span class="emphasis"><em>b</em></span> pattern, this can be done easily by
	starting a new line:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep 'a
b'</code></strong>
<strong class="userinput"><code>a</code></strong>
a
<strong class="userinput"><code>b</code></strong>
b
c
      </pre>

      <p>
	This works, because quotes are used, and the shell passes
	quoted parameters literally. Though, it must be admitted that
	this is not quite pretty. <span class="command"><strong>grep</strong></span> accepts one
	or more <em class="parameter"><code>-e pattern</code></em>
	parameters, giving the opportunity to specify more than one
	parameter on one line. The <span class="command"><strong>grep</strong></span> invocation
	in the previous example could be rewritten as:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>grep -e 'a' -e 'b'</code></strong>
      </pre>
    </div>
  </div>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.idm950899036" class="footnote"><p><a href="#idm950899036" class="para"><sup class="para">[6] </sup></a>Of course, that will not really
      matter in this case, because we don't use numbers higher than 9,
      and virtually all character sets have numbers in a numerical
      order.</p></div>
</div>
</div>
    <div lang="en" class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-procmgmt"></a>Chapter 10. Process management</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-procmgmt-theory">10.1. Theory</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-analyzing">10.2. Analyzing running processes</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-managing">10.3. Managing processes</a></span></dt>
<dt><span class="sect1"><a href="#chap-procmanagement-jobcontrol">10.4. Job control</a></span></dt>
</dl>
</div>

  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-procmgmt-theory"></a>10.1. Theory</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-procmgmt-theory-proc"></a>10.1.1. Processes</h3></div></div></div>
      

      <p>
	A running instance of a program is called a
	<span class="emphasis"><em>process</em></span>. Each process has its own
	protected memory, named the <span class="emphasis"><em>process address
	space</em></span>. This address space consists of two areas:
	the <span class="emphasis"><em>text area</em></span> and the <span class="emphasis"><em>data
	area</em></span>. The text area contains the actual program
	code, and tells the system what to do. The data area stores
	constant and runtime data of a process. Since there are many
	processes on a system, and only one or a few processors, the
	operating system kernel divides processor time between
	processes. This process is called
	<span class="emphasis"><em>time-sharing</em></span>.
      </p>

      <div class="table">
<a name="chap-procmgmt-theory-proc-struct"></a><p class="title"><b>Table 10.1. The structure of a process</b></p>
<div class="table-contents">
	

	<table summary="The structure of a process" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Field</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td>pid</td>
<td>The numeric process identifier</td>
</tr>
<tr>
<td>ppid</td>
<td>The process identifier of the
	      parent process</td>
</tr>
<tr>
<td>euid</td>
<td>The effective user ID of the
	      process.</td>
</tr>
<tr>
<td>ruid</td>
<td>The real user ID of the process</td>
</tr>
<tr>
<td>egid</td>
<td>The group ID of the process</td>
</tr>
<tr>
<td>rgid</td>
<td>The real group ID of the
	      process</td>
</tr>
<tr>
<td>fd</td>
<td>Pointer to the list of open file
	      descriptors</td>
</tr>
<tr>
<td>vmspace</td>
<td>Pointer to the process
	      address space.</td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
	<a class="xref" href="#chap-procmgmt-theory-proc-struct" title="Table 10.1. The structure of a process">Table 10.1, “The structure of a process”</a> lists the
	most important fields of information that a kernel stores
	about a process. Each process can be identified uniquely by
	its <span class="emphasis"><em>PID</em></span> (process identifier), which is an
	unsigned number. As we will see later, a user can easily
	retrieve the PID of a process. Each process is associated with
	a <span class="emphasis"><em>UID</em></span> (user ID) and
	<span class="emphasis"><em>GID</em></span> (group ID) on the system. Each
	process has a <span class="emphasis"><em>real UID</em></span>, which is the UID
	as which the process was started, and the <span class="emphasis"><em>effective
	UID</em></span>, which is the UID as which the process
	operates. Normally, the effective UID is equal to the real
	UID, but some programs ask the system to change its effective
	UID. The effective UID is used for access
	control. This means that if a user named joe starts a command,
	say less, less can only open files that joe has read rights
	for. In parallel, a process also has an <span class="emphasis"><em>real
	GID</em></span> and an <span class="emphasis"><em>effective GID</em></span>.
      </p>

      <p>
	Many processes open files, the handle used to operate on a
	file is called a <span class="emphasis"><em>file descriptor</em></span>. The
	kernel manages a list of open file descriptors for each
	process. The <span class="emphasis"><em>fd</em></span> field contains a pointer
	to the list of open files. The <span class="emphasis"><em>vmspace</em></span>
	field points to the process address space of the process.
      </p>

      
      <div class="figure">
<a name="chap-procmgmt-theory-proc-procstates"></a><p class="title"><b>Figure 10.1. Process states</b></p>
<div class="figure-contents">
	

	<div class="mediaobject"><img src="../../images/procstates.png" alt="Process states"></div>
      </div>
</div>
<br class="figure-break">

      <p>
	Not every process is in need of CPU time at a given
	moment. For instance, some processes maybe waiting for some
	<span class="emphasis"><em>I/O</em></span> (Input/Output) operation to complete
	or may be terminated. Not taking subtleties in account,
	processes are normally <span class="emphasis"><em>started</em></span>,
	<span class="emphasis"><em>running</em></span>, <span class="emphasis"><em>ready</em></span> (to
	run), <span class="emphasis"><em>blocked</em></span> (waiting for I/O), or
	<span class="emphasis"><em>terminated</em></span>. <a class="xref" href="#chap-procmgmt-theory-proc-procstates" title="Figure 10.1. Process states">Figure 10.1, “Process states”</a> shows the
	lifecycle of a process. A process that is terminated, but for
	which the process table entry is not reclaimed, is often
	called a <span class="emphasis"><em>zombie process</em></span>. Zombie processes
	are useful to let the parent process read the exit status of
	the process, or reserve the process table entry temporarily.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-procmgmt-theory-proc-new"></a>10.1.2. Creating new processes</h3></div></div></div>
      

      <p>
	New processes are created with the <span class="emphasis"><em>fork()</em></span>
	system call. This system call copies the process address space
	and process information of the caller, and gives the new
	process, named the child process, a different PID. The child
	process will continue execution at the same point as the
	parent, but will get a different return value from the
	<span class="emphasis"><em>fork()</em></span> system call. Based on this return
	value the code of the parent and child can decide how to
	continue executing. The following piece of C code shows a
	<span class="emphasis"><em>fork()</em></span> call in action:
      </p>

      <pre class="programlisting">
#include &lt;sys/types.h&gt;
#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;

int main() {
  pid_t pid = fork();
  if (pid == 0)
    printf("Hi, I am the child!\n");
  else
    printf("Hi, I am the parent, the child PID is %d!\n", pid);

  return 0;
}
      </pre>

      <p>
.	This little program calls <span class="emphasis"><em>fork()</em></span>, storing
	the return value of <span class="emphasis"><em>fork()</em></span> in the
	variable
	<span class="emphasis"><em>pid</em></span>. <span class="emphasis"><em>fork()</em></span> returns
	the value <span class="emphasis"><em>0</em></span> to the child, and the PID of
	the child to the parent. Since this is the case, we can use a
	simple conditional structure to check the value of the
	<span class="emphasis"><em>pid</em></span> variable, and print an appropriate
	message.
      </p>

      <p>
	You may wonder how it is possible to start new programs, since
	the <span class="emphasis"><em>fork()</em></span> call duplicates an existing
	process. That is a good question, since with
	<span class="emphasis"><em>fork()</em></span> alone, it is not possible to
	execute new programs. UNIX kernels also provide a set of
	system calls, starting with <span class="emphasis"><em>exec</em></span>, that
	load a new program image in the current process. We saw at the
	start of this chapter that a process is a running program -- a
	process was constructed in memory from the program image that
	is stored on a storage medium. So, the
	<span class="emphasis"><em>exec</em></span> family of system calls gives a
	running process the facilities to replace its contents with a
	program stored on some medium. In itself, this is not wildly
	useful, because every time the an <span class="emphasis"><em>exec</em></span>
	call is done, the original calling code (or program) is
	removed from the process. This can be witnessed in the following
	C program:
      </p>

      <pre class="programlisting">
#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;

int main() {
  execve("/bin/ls", NULL, NULL);

  /* This will never be printed, unless execve() fails. */
  printf("Hello world!\n");

  return 0;
}
      </pre>

      <p>
	This program executes <span class="command"><strong>ls</strong></span> with the
	<span class="emphasis"><em>execve()</em></span> call. The message printed with
	<span class="emphasis"><em>printf()</em></span> will never be shown, because the
	running program image is replaced with that of
	<span class="command"><strong>ls</strong></span>. Though, a combination of
	<span class="emphasis"><em>fork()</em></span> and the <span class="emphasis"><em>exec</em></span>
	functions are very powerful. A process can fork itself, and
	let the child <span class="quote">“<span class="quote">sacrifice</span>”</span> itself to run another
	program. The following program demonstrates this pattern:
      </p>

      <pre class="programlisting">
#include &lt;sys/types.h&gt;
#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;

int main() {
  pid_t pid = fork();
  if (pid == 0)
    execve("/bin/ls", NULL, NULL);

  printf("Hello world!");

  return 0;
}
      </pre>

      <p>
	This program forks itself first. The program image of the
	child process will be replaced with <span class="command"><strong>ls</strong></span>,
	while the parent process prints the <span class="quote">“<span class="quote">Hello world!</span>”</span>
	message to the screen and returns.
      </p>

      <p>
	This procedure is followed by many programs, including the
	shell, when a command is executed from the shell prompt. In
	fact all processes on a UNIX system are directly or indirectly
	derrived from the <span class="emphasis"><em>init</em></span> process, which is
	the first program that is started on a UNIX system.
      </p>

      
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-procmgmt-theory-proc-threads"></a>10.1.3. Threads</h3></div></div></div>
      

      <p>
	Although forks are very useful to build some
	parallelism<a href="#ftn.idm950738716" class="footnote" name="idm950738716"><sup class="footnote">[7]</sup></a>, they can be to expensive for some
	purposes. Copying the whole process takes some time, and there
	is cost involved if processes want to share data. This is
	solved by offering a more lightweight alternative, namely
	allowing more than one thread of execution. Each thread of
	execution is executed separately, but the process data is
	shared between the threads.
      </p>

      <p>
	Writing good <span class="emphasis"><em>multithreaded</em></span> programs
	requires good knowledge of data sharing and locking. Since all
	data is shared, uncareful programming can lead to bugs like
	race conditions.
      </p>
    </div>

    
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-procmanagement-analyzing"></a>10.2. Analyzing running processes</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-procmanagement-analyzing-listing"></a>10.2.1. Listing running processes</h3></div></div></div>
      

      <p>
	UNIX systems provide the <span class="command"><strong>ps</strong></span> command to show
	a list of running processes. Unfortunately, this command is an
	example of the pains of the lack of standardization. The BSD
	and System V variants of <span class="command"><strong>ps</strong></span> have their own
	sets of options. Fortunately, GNU/Linux implements both the
	System V and BSD-style parameters, as well as some (GNU-style)
	long options. Options preceded by a dash are interpreted as
	System V options and options without a dash as BSD options.
	We will describe the System V-style options in this section.
      </p>

      <p>
	If <span class="command"><strong>ps</strong></span> is used without any parameters, it
	shows all processes owned by the user that invokes
	<span class="command"><strong>ps</strong></span> and that are attached to the same
	controlling terminal. For example:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ps</code></strong>
  PID TTY          TIME CMD
 8844 pts/5    00:00:00 bash
 8862 pts/5    00:00:00 ps
      </pre>

      <p>
	A lot of useful information can be distilled from this
	output. As you can see, two processes are listed: the shell
	that we used to call <span class="command"><strong>ps</strong></span>
	(<span class="emphasis"><em>bash</em></span>), and the <span class="command"><strong>ps</strong></span>
	command itself. In this case there are four information
	fields. <span class="emphasis"><em>PID</em></span> is the process ID of a
	process, <span class="emphasis"><em>TTY</em></span> the controlling terminal,
	<span class="emphasis"><em>TIME</em></span> the amount of CPU time the proces
	has used, and <span class="command"><strong>CMD</strong></span> the command or program of
	which a copy is running. The fields that are shown by default
	may vary a bit per system, but usually at least these fields
	are shown, with somewhat varying field labels.
      </p>

      <p>
	Sometime you may want to have a broader view of processes that
	are running. Adding the <em class="parameter"><code>-a</code></em> option shows all processes that
	are associated with terminals. For instance:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ps -a</code></strong>
  PID TTY          TIME CMD
 7487 pts/1    00:00:00 less
 8556 pts/4    00:00:10 emacs-x
11324 pts/3    00:00:00 ps
      </pre>

      <p>
	As you can see, processes with different controlling terminals
	are shown. Though, in contrast to the plain
	<span class="command"><strong>ps</strong></span> output, only processes that control the
	terminal at the moment are shown. For instance, the shell that
	was used to call <span class="command"><strong>ps</strong></span> is not shown.
      </p>

      <p>
	You can also print all processes that are running, including
	processes that are not associated with a terminal, by using the
	<em class="parameter"><code>-A</code></em> option:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ps -A | head -n 10</code></strong>
  PID TTY          TIME CMD
    1 ?        00:00:01 init
    2 ?        00:00:00 migration/0
    3 ?        00:00:00 ksoftirqd/0
    4 ?        00:00:00 watchdog/0
    5 ?        00:00:00 migration/1
    6 ?        00:00:00 ksoftirqd/1
    7 ?        00:00:00 watchdog/1
    8 ?        00:00:00 events/0
    9 ?        00:00:00 events/1
      </pre>

      <p>
	You can print all processes with a certain user ID, with the
	<span class="emphasis"><em>-U</em></span> option. This option accepts a user
	name as a parameter, or multiple user names that are separated
	by a comma. The following command shows all processes that
	have <span class="emphasis"><em>xfs</em></span> or <span class="emphasis"><em>rpc</em></span> as
	their user ID:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ps -U xfs,rpc</code></strong>
  PID TTY          TIME CMD
 2409 ?        00:00:00 portmap
 2784 ?        00:00:00 xfs
      </pre>

      <p>
	Likewise, you can also print processes with a particular group
	ID, with the <span class="emphasis"><em>-G</em></span> option:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ps -G messagebus,haldaemon</code></strong>
  PID TTY          TIME CMD
 8233 ?        00:00:00 dbus-daemon
11312 ?        00:00:00 hald
11320 ?        00:00:00 hald-addon-keyb
11323 ?        00:00:00 hald-addon-acpi
      </pre>

      <p>
	If you would like to have a list for a physical or
	pseudo-terminal, you can use the <em class="parameter"><code>-t</code></em> option:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>ps -t tty2</code></strong>
  PID TTY          TIME CMD
 2655 tty2     00:00:00 getty
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-procmanagement-managing"></a>10.3. Managing processes</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-procmanagement-managing-signals"></a>10.3.1. Sending signals to a process</h3></div></div></div>
      

      <p>
	Signals are a crude, but effective form of inter-process
	communication (IPC). A signal is basically a number that is
	delivered to a process that has a special meaning. For all
	signals there are default signal handlers. Processes can
	install their own signal handlers, or choose to ignore
	signals. Some signals (normally SIGKILL and SIGSTOP) can not
	be ignored. All signals have convenient symbolic names.
      </p>

      <p>
	Only a few signals are normally interesting for interactive
	use on UNIX(-like) systems. These are (followed by their number):
      </p>

      <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	  <p><span class="emphasis"><em>SIGKILL (9):</em></span> forcefully kill
	  a process.</p>
	</li>
<li class="listitem">
	  <p><span class="emphasis"><em>SIGTERM (15):</em></span> request a process
	  to terminate. Since this is a request, a program could ignore
	  it, in contrast to <span class="emphasis"><em>SIGKILL</em></span>.</p>
	</li>
<li class="listitem">
	  <p><span class="emphasis"><em>SIGHUP (1):</em></span> Traditionally, this
	  has signalled a terminal hangup. But nowadays some daemons
	  (e.g. <span class="emphasis"><em>inetd</em></span>) reread their configuration
	  when this signal is sent.</p>
	</li>
</ul></div>

      <p>
	The <span class="command"><strong>kill</strong></span> command is used to send a signal
	to a process. By default, <span class="command"><strong>kill</strong></span> sends the
	<span class="emphasis"><em>SIGTERM</em></span> signal. To send this signal, the
	process ID of the process that you would like to send this
	signal to should be added as a parameter. For instance:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>kill 15631</code></strong>
      </pre>

      <p>
	To send another signal, you can use one of two options:
	<span class="emphasis"><em>-signalnumber</em></span> or
	<span class="emphasis"><em>-signalname</em></span>. So, the following commands
	both send the <span class="emphasis"><em>SIGKILL</em></span> signal to the process
	with process ID <span class="emphasis"><em>15631</em></span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>kill -9 15631</code></strong>
      </pre>

      <pre class="screen">
$ <strong class="userinput"><code>kill -SIGKILL 15631</code></strong>
      </pre>

      
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-procmanagement-managing-nice"></a>10.3.2. Being nice to others</h3></div></div></div>
      

      <p>
	In an act of altruism you can be nice to other users of
	computer resources. If you plan to run a CPU-time intensive
	process, but do not want that to interfere with work of other
	users on the system (or other processes), you can assign some
	grade of 'niceness' to a process. Practically, this means that
	you will be able to influence the scheduling priority of a
	process. Nicer processes get a lower scheduling priority. The
	normal niceness of a process is <span class="emphasis"><em>0</em></span>, and
	can be changed by executing a program with the
	<span class="command"><strong>nice</strong></span> command. The <span class="emphasis"><em>-n
	[niceness]</em></span> option can be used to specify the
	niceness:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>nice -n 20 cputimewaster</code></strong>
      </pre>

      <p>
	The maximum number for niceness is
	implementation-dependent. If a program was started with
	<span class="command"><strong>nice</strong></span>, but no niceness was specified, the
	niceness will be set to <span class="emphasis"><em>10</em></span>. In case you
	were wondering: yes, you can also be rude, but this right is
	restricted to the <span class="emphasis"><em>root</em></span> user. You can
	boost the priority of a process by specifying a negative value
	as the niceness.
      </p>

      <p>
	You can also modify the niceness of a running processes with
	the <span class="command"><strong>renice</strong></span> command. This can be done for
	specific process IDs (<em class="parameter"><code>-p
	PIDs</code></em>), users (<em class="parameter"><code>-u
	user/uid</code></em>), and effective groups (<em class="parameter"><code>-g group/gid</code></em>). The new niceness
	is specified as the first parameter.
      </p>

      <p>
	The niceness of a process can only be increased. And, of
	course, no user except for <span class="emphasis"><em>root</em></span> can
	affect the niceness of processes of other users.
      </p>

      <p>
	Lets look at an example, to set the niceness of a process with
	PID <span class="emphasis"><em>3108</em></span> to <span class="emphasis"><em>14</em></span>, you
	could use the following command:
      </p>

      <pre class="screen">
$ <span class="command"><strong>renice 14 -p 3108</strong></span>
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-procmanagement-jobcontrol"></a>10.4. Job control</h2></div></div></div>
    

    <p>
      It is often useful to group processes to allow operations on a
      set of processes, for instance to distribute a signal to all
      processes in a group rather than a single process. Not too
      suprisingly, these sets of processes are called
      <span class="emphasis"><em>program groups</em></span> in UNIX. After a fork, a
      child process is automatically a member of the process group of
      the parent. Though, new process groups can be created by making
      one process a process group leader, and adding other processes
      to the group. The process group ID is the PID of the process
      group leader.
    </p>

    <p>
      Virtually all modern UNIX shells give processes that are created
      through the invocation of a command their own process group. All
      processes in a pipeline are normally added to one process group.
      In the following commands that create a pipeline are executed
    </p>

    <pre class="screen">
cat | tr -s ' ' | egrep 'foob.r'
    </pre>

    <p>
      the shell roughly performs the following steps:
    </p>

    <div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
	<p>
	  Three child processes are forked.
	</p>
      </li>
<li class="listitem">
	<p>
	  The first process in the pipeline is put in a process group
	  with its own PID as the process group ID, making it the
	  process leader. The other processes in the pipeline are added
	  to the process group.
	</p>
      </li>
<li class="listitem">
	<p>
	  The file descriptors of the processes in the pipeline are
	  reconfigured to form a pipeline.
	</p>
      </li>
<li class="listitem">
	<p>
	  The programs in the pipeline are executed.
	</p>
      </li>
</ol></div>

    <p>
      The shell uses process groups to implement <span class="emphasis"><em>job
      control</em></span>. A shell can run multiple jobs in the
      background, there can be multiple stopped job, and one job can
      be in the foreground. A foreground job is wired to the terminal
      for its standard input (meaning that it is the job the gets user
      input).
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-procmgmt-jobcontrol-stopping"></a>10.4.1. Stopping and continuing a job</h3></div></div></div>
      
      
      <p>
	A job that is in the foreground (thus, a job that potentially
	accepts user input from the terminal) can be stopped by
	pressing <span class="emphasis"><em>Ctrl-z</em></span> (pressing both the 'Ctrl' and
	'z' keys simultaneously). This will stop the job,
	and will handle control over the terminal back to the shell.
	Let's try this with the <span class="command"><strong>sleep</strong></span> command, which
	waits for the number of seconds provided as an argument:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>sleep 3600</code></strong>
<strong class="userinput"><code>Ctrl-z</code></strong>
[1]+  Stopped                 sleep 3600
      </pre>

      <p>
	The process group, which we will refer to as a job has been
	stopped now, meaning that the <span class="command"><strong>sleep</strong></span> has
	stopped counting - it's execution is completely stopped. You
	can retrieve a list of jobs with the <span class="command"><strong>jobs</strong></span>
	command:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>jobs</code></strong>
[1]+  Stopped                 sleep 3600
      </pre>

      <p>
	This shows the job number (<span class="emphasis"><em>1</em></span>), its state,
	and the command that was used to start this job. Let's run
	another program, stop that too, and have another look at the
	job listing.
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cat</code></strong>
<strong class="userinput"><code>Ctrl-z</code></strong>
[2]+  Stopped                 cat
$ <strong class="userinput"><code>jobs</code></strong>
[1]-  Stopped                 sleep 3600
[2]+  Stopped                 cat
      </pre>

      <p>
	As expected, the second job is also stopped, and was assigned
	job number <span class="emphasis"><em>2</em></span>. The plus sign
	(<span class="emphasis"><em>+</em></span>) following the first job has changed
	to a minus (<span class="emphasis"><em>-</em></span>) sign, while the second job
	is now marked by a plus sign. The plus sign is used to
	indicate the <span class="emphasis"><em>current job</em></span>. The
	<span class="command"><strong>bg</strong></span> and <span class="command"><strong>fg</strong></span> commands that
	we will look at shortly, will operate on the current job
	if no job was specified as a parameter.
      </p>
     
      

      <p>
	Usually, when you are working with jobs, you will want to move
	jobs to the foreground again. This is done with the
	<span class="command"><strong>fg</strong></span> command. Executing <span class="command"><strong>fg</strong></span>
	without a parameter will put the current job in the
	foreground.  Most shells will print the command that is moved
	to the foreground to give an indication of what process was
	moved to the foreground:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>fg</code></strong>
cat
      </pre>

      <p>
	Of course, it's not always useful to put the current job in
	the foreground. You can put another job in the foreground by
	adding the job number preceded by the percentage sign
	(<span class="emphasis"><em>%</em></span>) as an argument to
	<span class="command"><strong>fg</strong></span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>fg %1</code></strong>
sleep 3600
      </pre>

      <p>
	Switching jobs by stopping them and putting them in the
	foreground is often very useful when the shell is used
	interactively. For example, suppose that you are editing a
	file with a text editor, and would like to execute some other
	command and then continue editing. You could stop the editor
	with <span class="emphasis"><em>Ctrl-z</em></span>, execute a command, and put
	the editor in the foreground again with <span class="command"><strong>fg</strong></span>.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-procmgmt-jobcontrol-background"></a>10.4.2. Background jobs</h3></div></div></div>
      

      <p>
	Besides running in the foreground, jobs can also run in the
	background. This means that they are running, but input from
	the terminal is not redirected to background processes. Most
	shells do configure background jobs to direct output to the
	terminal of the shell where they were started.
      </p>

      <p>
	A process that is stopped can be continued in the background
	with the <span class="command"><strong>bg</strong></span> command:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>sleep 3600</code></strong>
  
[1]+  Stopped                 sleep 3600
$ <strong class="userinput"><code>bg</code></strong>
[1]+ sleep 3600 &amp;
$
      </pre>

      <p>
	You can see that the job is indeed running with
	<span class="command"><strong>jobs</strong></span>:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>jobs</code></strong>
[1]+  Running                 sleep 3600 &amp;
      </pre>

      <p>
	Like <span class="command"><strong>fg</strong></span>, you can also move another job than
	the current job to the background by specifying its job
	number:
      </p>

      <pre class="screen">
$ <span class="command"><strong>bg %1</strong></span>
[1]+ sleep 3600 &amp;
      </pre>

      <p>
	You can also put a job directly in the background when it is
	started, by adding an trailing ampersand (&amp;) to a command
	or pipeline. For instance:
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>sleep 3600 &amp;</code></strong>
[1] 5078
      </pre>

      
    </div>
  </div>
<div class="footnotes">
<br><hr style="width:100; text-align:left;margin-left: 0">
<div id="ftn.idm950738716" class="footnote"><p><a href="#idm950738716" class="para"><sup class="para">[7] </sup></a>For instance, a web server could
	fork multiple child processes to handle
	requests</p></div>
</div>
</div>
  </div>

  <div class="part">
<div class="titlepage"><div><div><h1 class="title">
<a name="editing"></a>Part III. Editant i formatant text ??"typesetting"??</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="chapter"><a href="#editing-latex">11. LaTeX</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#editing-latex-introduction">11.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#editing-latex-basic">11.2. Preparing basic LaTeX documents</a></span></dt>
</dl></dd>
</dl>
</div>
    
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="editing-latex"></a>Chapter 11. LaTeX</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#editing-latex-introduction">11.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#editing-latex-basic">11.2. Preparing basic LaTeX documents</a></span></dt>
</dl>
</div>
<a class="indexterm" name="idm950683412"></a><a class="indexterm" name="idm950683156"></a><div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="editing-latex-introduction"></a>11.1. Introduction</h2></div></div></div>
<p>
      LaTeX is a typesetting system that can be used to produce high-quality
      articles, books, letters and other publications. LaTeX is based on
      TeX, a lower-level typesetting language that was designed by Donald
      E. Knuth. LaTeX does not work like a <acronym class="acronym">WYSIWYG</acronym>
      (what you see is what you get) word processor, the kind of document
      preparation system most people are accustomed to. With LaTeX you
      do not have to care about formatting the document, only about writing
      the document.
    </p>
<p>
      LaTeX files are plain-text files that contain LaTeX macros. LaTeX
      formats the document based on the macros that are used. In the
      beginning using LaTeX may be a bit awkward to a new user. But after
      a while you will discover that using LaTeX has some distinct
      advantages. To name a few:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
          LaTeX-formatted documents look very professional.
        </p></li>
<li class="listitem"><p>
          You do not have to care about the layout of your documents. You
          just add structure to your documents, and LaTeX takes care of
          the formatting.
        </p></li>
<li class="listitem"><p>
          LaTeX files are plain text, and can easily be changed using
          standard UNIX tools, such as <span class="command"><strong>vi</strong></span>,
          <span class="command"><strong>sed</strong></span> or <span class="command"><strong>awk</strong></span>
        </p></li>
<li class="listitem"><p>
          LaTeX provides very good support for typesetting things like
          mathematical formula, references and Postscript images.
        </p></li>
</ul></div>
<p>
      LaTeX is very extensive, so this chapter will only touch the
      surface of LaTeX. But it should be enough to get you started
      to be able to make simple documents.
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="editing-latex-basic"></a>11.2. Preparing basic LaTeX documents</h2></div></div></div>
<a class="indexterm" name="idm950678404"></a><a class="indexterm" name="idm950678084"></a><div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="editing-latex-basic-minimal"></a>11.2.1. Minimal document structure</h3></div></div></div>
<p>
        Each LaTeX document has some basic minimal structure that
        describes the document. Let's look at an example:
      </p>
<pre class="screen">
\documentclass[10pt,a4paper]{article} <a name="latex-struct-1"></a><span><img src="../images/callouts/1.png" alt="1" border="0"></span>

\title{The history of symmetric ciphers} <a name="latex-struct-2"></a><span><img src="../images/callouts/2.png" alt="2" border="0"></span>
\author{John Doe} <a name="latex-struct-3"></a><span><img src="../images/callouts/3.png" alt="3" border="0"></span>

\begin{document} <a name="latex-struct-4"></a><span><img src="../images/callouts/4.png" alt="4" border="0"></span>

This is a basic document. <a name="latex-struct-5"></a><span><img src="../images/callouts/5.png" alt="5" border="0"></span>

\end{document} <a name="latex-struct-6"></a><span><img src="../images/callouts/6.png" alt="6" border="0"></span>
      </pre>
<p>
        You can already see the basic syntactical structure of LaTeX
        commands. A command is started with a backslash, followed by the
        name of the command. Each macro has a mandatory argument that
        is placed in accolades, and an optional argument that is placed
        in square brackets.
      </p>
<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a href="#latex-struct-1"><span><img src="../images/callouts/1.png" alt="1" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
            The first command in every document is the
            <span class="emphasis"><em>documentclass</em></span>. This command specifies
            what kind of document LaTeX is dealing with. The type of
            document is specified as a mandatory parameter. You can
            also specify some optional parameters, such as the font
            size and the paper size. In this case the font size is changed
            from the default 12pt to 10pt, and A4 is used as the
            paper size. The document classes that are available in
            LaTeX are shown in <a class="xref" href="#latex-documentclasses" title="Table 11.1. LaTeX document classes">Table 11.1, “LaTeX document classes”</a>.
          </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#latex-struct-2"><span><img src="../images/callouts/2.png" alt="2" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
            After the documentclass you can add some meta-information
            to the document, like the title of the document. In this
            case the title is <span class="emphasis"><em>The history of symmetric 
            ciphers</em></span>.
          </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#latex-struct-3"><span><img src="../images/callouts/3.png" alt="3" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
            The author command specifies the author of the book.
          </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#latex-struct-4"><span><img src="../images/callouts/4.png" alt="4" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
            The <span class="emphasis"><em>\begin</em></span> command marks the beginning
            of an environment. There are many different environments,
            but they all implicate certain typesetting conventions for the
            text that is in an environment. In this case we start an
            <span class="emphasis"><em>document</em></span> environment. This is a very
            basic environment, LaTeX interprets everything in this
            environment as the body of the text.
          </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#latex-struct-5"><span><img src="../images/callouts/5.png" alt="5" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
            The content of the document can be placed within the
            <span class="emphasis"><em>document</em></span>, in this case a friendly
            warning about the nature of the document.
          </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#latex-struct-6"><span><img src="../images/callouts/6.png" alt="6" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
            All environments eventually have to be closed. The
            <span class="emphasis"><em>document</em></span> environment is the last
            environment that is closed, because it denotes the end
            of the body of the text.
          </p></td>
</tr>
</table></div>
<div class="table">
<a name="latex-documentclasses"></a><p class="title"><b>Table 11.1. LaTeX document classes</b></p>
<div class="table-contents"><table summary="LaTeX document classes" border="1">
<colgroup><col></colgroup>
<thead><tr><th>Class</th></tr></thead>
<tbody>
<tr><td>article</td></tr>
<tr><td>book</td></tr>
<tr><td>letter</td></tr>
<tr><td>report</td></tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="editing-latex-basic-print"></a>11.2.2. Generating printable formats</h3></div></div></div>
<p>
        Once you have a LaTeX file, you can use the <span class="command"><strong>latex</strong></span>
        command to generate a <acronym class="acronym">DVI</acronym> (Device Independent
        format) file:
      </p>
<pre class="screen">
$ <span class="command"><strong>latex crypto.tex</strong></span>
This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
entering extended mode
(./crypto.tex
LaTeX2e &lt;2003/12/01&gt;
Babel &lt;v3.8d&gt; and hyphenation patterns for american, french, german, ngerman, b
ahasa, basque, bulgarian, catalan, croatian, czech, danish, dutch, esperanto, e
stonian, finnish, greek, icelandic, irish, italian, latin, magyar, norsk, polis
h, portuges, romanian, russian, serbian, slovak, slovene, spanish, swedish, tur
kish, ukrainian, nohyphenation, loaded.
(/usr/share/texmf/tex/latex/base/article.cls
Document Class: article 2004/02/16 v1.4f Standard LaTeX document class
(/usr/share/texmf/tex/latex/base/size10.clo)) (./crypto.aux) [1] (./crypto.aux)
 )
 Output written on crypto.dvi (1 page, 248 bytes).
 Transcript written on crypto.log.
      </pre>
<p>
        As the LaTeX command reports a DVI file is created after running
        the <span class="command"><strong>latex</strong></span> command. You can view this file with
        an X viewer for DVI files, <span class="command"><strong>xdvi</strong></span>:
      </p>
<pre class="screen">
$ <span class="command"><strong>xdvi crypto.dvi</strong></span>
      </pre>
<p>
        This file is not directly printable (although DVI files can be
        printed with <span class="command"><strong>xdvi</strong></span>). An ideal format for
        printable files is Postscript. You can generate a Postscript
        file from the DVI file with one simple command:
      </p>
<pre class="screen">
$ <span class="command"><strong>dvips -o crypto.ps crypto.dvi</strong></span>
      </pre>
<p>
        The <em class="parameter"><code>-o</code></em> specifies the output
        (file) for the Postscript document. If this parameter is not
        specified, the output will be piped through <span class="command"><strong>lpr</strong></span>,
        which will schedule the document to be printed.
      </p>
<p>
        <acronym class="acronym">PDF</acronym> (Portable Document Format) is another
        popular format for electronic documents. PDF can easily be
        generated from Postscript:
      </p>
<pre class="screen">
$ <span class="command"><strong>ps2pdf crypto.ps</strong></span>
      </pre>
<p>
        The resulting output file will be the same as the input file,
        with the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.ps</code></html:span> extension replaced with
        <span class="command"><strong>.pdf</strong></span>.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="editing-latex-basic-sections"></a>11.2.3. Sections</h3></div></div></div>
<a class="indexterm" name="idm950660396"></a><p>
        Now that you know how to create a basic LaTeX document, it is
        a good time to add some more structure. Structure is added using
        sections, subsections, and subsubsections. These structural
        elements are made with respectively the <span class="emphasis"><em>\section</em></span>,
        <span class="emphasis"><em>\subsection</em></span> and
        <span class="emphasis"><em>\subsubsection</em></span> commands. The mandatory parameter
        for a section is the title for the section. Normal sections,
        subsections and subsubsections are automatically numbered, and
        added to the table of contents. By adding a star after a section
        command, for example <span class="emphasis"><em>\section*{title}</em></span> section
        numbering is suppressed, and the section is not added to the
        table of contents. The following example demonstrates how
        you can use sections:
      </p>
<pre class="screen">
\documentclass[10pt,a4paper]{article}

\title{The history of symmetric ciphers}
\author{John Doe}

\begin{document}

\section{Pre-war ciphers}

To be done.

\section{Modern ciphers}

\subsection*{Rijndael}

Rijndael is a modern block cipher that was designed by Joan Daemen and
Vincent Rijmen. 

In the year 2000 the US National Institute of Standards and Technologies
selected Rijndael as the winner in the contest for becoming the Advanced
Encryption Standard, the successor of DES.

\end{document}
      </pre>
<p>
        The example above is pretty straightforward, but this is a good
        time to look at how LaTeX treats end of line characters and empty
        lines. Empty lines are ignored by LaTeX, making the text a
        continuous flow. An empty line starts a new paragraph. All paragraphs
        but the first paragraph are started with a extra space left of the
        first word.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="editing-latex-basic-fontstyle"></a>11.2.4. Font styles</h3></div></div></div>
<p>
        Usually you may want to work with different font styles too. LaTeX
        has some commands that can be used to change the appearance of the
        current font. The most commonly used font commands are
        <span class="emphasis"><em>\emph</em></span> for emphasized text, and
        <span class="emphasis"><em>\textbf</em></span>. Have a look at <a class="xref" href="#latex-fontstyles" title="Table 11.2. LaTeX font styles">Table 11.2, “LaTeX font styles”</a> for a more extensive list of font
        styles. Emphasis and bold text are demonstrated in this example
        paragraph:
      </p>
<pre class="screen">
Working with font styles is easy. \emp{This text is emphasized} and
\textbf{this text is bold}.
      </pre>
<div class="table">
<a name="latex-fontstyles"></a><p class="title"><b>Table 11.2. LaTeX font styles</b></p>
<div class="table-contents"><table summary="LaTeX font styles" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Command</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td>\emph</td>
<td>Add emphasis to a font.</td>
</tr>
<tr>
<td>\textbf</td>
<td>Print the text in bold.</td>
</tr>
<tr>
<td>\textit</td>
<td>Use an italic font.</td>
</tr>
<tr>
<td>\textsl</td>
<td>Use a font that is slanted.</td>
</tr>
<tr>
<td>\textsc</td>
<td>Use small capitals.</td>
</tr>
<tr>
<td>\texttt</td>
<td>Use a typewriter font.</td>
</tr>
<tr>
<td>\textsf</td>
<td>Use a sans-serif font.</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
</div>
</div>
  </div>

  <div class="part">
<div class="titlepage"><div><div><h1 class="title">
<a name="email"></a>Part IV. Correu electrònic</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="chapter"><a href="#email-mutt">12. Reading and writing e-mail with mutt</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#email-mutt-introduction">12.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-usage">12.2. Usage</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-basicsetup">12.3. Basic setup</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-imap">12.4. Using IMAP</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-gnupg">12.5. Signing/encrypting e-mails</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#email-sendmail">13. Sendmail</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#email-sendmail-introduction">13.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#email-sendmail-installation">13.2. Installation</a></span></dt>
<dt><span class="sect1"><a href="#email-sendmail-configuration">13.3. Configuration</a></span></dt>
</dl></dd>
</dl>
</div>
    
    
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="email-mutt"></a>Chapter 12. Reading and writing e-mail with mutt</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#email-mutt-introduction">12.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-usage">12.2. Usage</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-basicsetup">12.3. Basic setup</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-imap">12.4. Using IMAP</a></span></dt>
<dt><span class="sect1"><a href="#email-mutt-gnupg">12.5. Signing/encrypting e-mails</a></span></dt>
</dl>
</div>
<a class="indexterm" name="idm950651012"></a><div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="email-mutt-introduction"></a>12.1. Introduction</h2></div></div></div>
<a class="indexterm" name="idm950650396"></a><a class="indexterm" name="idm950650156"></a><p>
      Mutt is a mail user agent (<acronym class="acronym">MUA</acronym>) that can be used
      for reading and writing e-mail. Mutt is a text-mode installation,
      meaning that it can be used on the console, over SSH and in an X
      terminal. Due to its menu interface, it is very easy to read large
      amounts of e-mail in a short time, and mutt can be configured to
      use your favorite text editor.
    </p>
<p>
      This chapter will discuss how you can customize mutt for your needs,
      how to use it, and how PGP/GnuPG support is used.
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="email-mutt-usage"></a>12.2. Usage</h2></div></div></div>
<p>
      Mutt is pretty simple to use, though it may take some time to get
      used to the keys that are used to navigate, read and write e-mails.
      The next few sections describe some of the most important keys. Mutt
      provides a more thorough overview of available keys after pressing
      the &lt;h&gt; key.
    </p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-mutt-usage-browsing"></a>12.2.1. Browsing the list of e-mails</h3></div></div></div>
<p>
        After invoking the <span class="command"><strong>mutt</strong></span> command, an overview
        of all e-mails will show up. You can browse through the list of
        e-mails with the up and down arrow keys, or the &lt;k&gt; and
        &lt;j&gt; keys. 
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-mutt-usage-reading"></a>12.2.2. Reading e-mails</h3></div></div></div>
<p>
        To read an e-mail, use the &lt;Enter&gt; key, after selecting an
        e-mail in the overview of e-mails.
        When reading an e-mail you can use the &lt;Page Up&gt; and
        &lt;Page Down&gt; to browse through an e-mail. You can still use
        the navigational keys used to browse the list of e-mail to browse
        to other e-mails.
      </p>
<p>
        If an e-mail has any attachments, you can see them by pressing
        the &lt;v&gt; key. You can view individual attachments by selecting
        them and pressing the &lt;Enter&gt; key. To save an attachment to
        a file, press the &lt;s&gt; key.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-mutt-usage-sending"></a>12.2.3. Sending e-mails</h3></div></div></div>
<p>
        You can compose a new e-mail with the &lt;m&gt; key, or reply
        to a selected e-mail with the &lt;r&gt; key. Mutt will ask you
        to specify the recipient (<span class="emphasis"><em>To:</em></span>), and a
        subject (<span class="emphasis"><em>Subject:</em></span>). After entering this
        information an editor is launched (<span class="command"><strong>vi</strong></span> is used
        by default), which you can use to compose the e-mail. After saving
        the e-mail, and quitting the editor, mutt will give you the
        opportunity to make any changes to the e-mail. If you decide
        that you want to alter the e-mail, you can restart the editor
        with the &lt;e&gt; key. You can change the recipient or the
        subject with respectively &lt;t&gt; or &lt;s&gt;. Finally, you
        can send the e-mail by pressing &lt;y&gt;. If you would like to
        cancel the e-mail, press &lt;q&gt;. Mutt will ask you whether you
        want to postpone the e-mail. If you do so, you will be given the
        opportunity to re-do the e-mail the next time you compose a
        message.
      </p>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="email-mutt-basicsetup"></a>12.3. Basic setup</h2></div></div></div>
<p>
      There are a few mutt settings you often want to configure. This section
      describes these settings. User-specific mutt customizations can be made
      in the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.muttrc</code></html:span> in the user's home directory. You
      can change global mutt settings in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mutt/Muttrc</code></html:span>.
    </p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-mutt-basicsetup-headers"></a>12.3.1. Customized headers</h3></div></div></div>
<a class="indexterm" name="idm950642228"></a><p>
        Each e-mail has headers with various information. For example, the
        header contains information about the path an e-mail has traversed
        after it has been sent. The sender (<span class="emphasis"><em>From:</em></span>) and
        recipient (<span class="emphasis"><em>To:</em></span>) e-mail addresses are also stored
        in the headers, as well as the subject (<span class="emphasis"><em>Subject:</em></span>)
        of an e-mail.
      </p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
          In reality the <span class="emphasis"><em>To:</em></span> header is not used to
          determine the destination of an e-mail during the deliverance
          process of the e-mail. MTAs use the <span class="emphasis"><em>envelope
          address</em></span> to determine the destination of the e-mail.
          Though, most MUAs use the <span class="emphasis"><em>To:</em></span> address that
          the user fills in as the envelope address.
        </p></td></tr>
</table></div>
<p>
        You can add your own headers to an e-mail with the
        <span class="emphasis"><em>my_hdr</em></span> configuration option. This option
        has the following syntax: <span class="emphasis"><em>my_hdr &lt;header name&gt;:
        &lt;header contents&gt;</em></span>. For example, you can add information
        about what OS you are running by adding the following line to your
        mutt configuration:
      </p>
<pre class="screen">
my_hdr X-Operating-System: Slackware Linux 10.2
      </pre>
<p>
        You can also override some of the headers that are normally used,
        such as the sender address that is specified in the
        <span class="emphasis"><em>From:</em></span> header:
      </p>
<pre class="screen">
my_hdr From: John Doe &lt;john.doe@example.org&gt;
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950637756"></a>12.3.2. The sendmail binary</h3></div></div></div>
<a class="indexterm" name="idm950637540"></a><p>
        By default mutt uses the sendmail MTA to deliver e-mails that
        were sent. You can use another command to send e-mail by altering
        the <span class="emphasis"><em>sendmail</em></span> configuration variable. The
        sendmail replacement must handle the same parameter syntax
        as sendmail. For example, if you have installed MSMTP to deliver
        e-mails, you can configure mutt to use it by adding the following
        line to your mutt configuration:
      </p>
<pre class="screen">
set sendmail="/usr/bin/msmtp"
      </pre>
<p>
        When you have completely replaced sendmail with another MTA, for
        instance Postfix, it is usually not needed to set this parameter,
        because most MTAs provide an alternative sendmail binary file.
      </p>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="email-mutt-imap"></a>12.4. Using IMAP</h2></div></div></div>
<p>
      Normally, mutt reads e-mail from the user's local spool mailbox.
      However, mutt also has support for using IMAP mailboxes.
      <acronym class="acronym">IMAP</acronym> (the Internet Message Access Protocol)
      is a protocol that is used for accessing e-mail from a remote
      server, and is supported by many e-mail servers. Mutt uses the
      following URL format for representing IMAP servers:
    </p>
<div class="literallayout"><p><br>
imap://[user@]hostname[:port]/[mailbox]<br>
    </p></div>
<p>
      Or the following format for IMAP over SSL/TLS:
    </p>
<div class="literallayout"><p><br>
imaps://[user@]hostname[:port]/[mailbox]<br>
    </p></div>
<p>
      You can directly use this syntax in folder-related operatings.
      For example, if you press <span class="quote">“<span class="quote">c</span>”</span> to change from folder,
      you can enter an IMAP URL. This is a bit tedious, so it is easier
      to store this information in your <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.muttrc</code></html:span> file.
    </p>
<p>
      If you use only one IMAP account, you can set the INBOX folder
      of this account as the spool mailbox, and the main IMAP account
      as the e-mail folder. For example, adding the following lines
      to your <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.muttrc</code></html:span> configuration file will set
      up mutt to log in to the <span class="emphasis"><em>imap.example.org</em></span>
      server as the <span class="emphasis"><em>me</em></span> user.
    </p>
<pre class="screen">
set folder=imap://me@imap.example.org/
set spoolfile=imap://me@imap.example.org/INBOX
    </pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="email-mutt-gnupg"></a>12.5. Signing/encrypting e-mails</h2></div></div></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-mutt-gnupg-introduction"></a>12.5.1. Introduction</h3></div></div></div>
<p>
        Mutt provides excellent support for signing or encrypting e-mails
        with GnuPG. One might wonder why he or she should use one of these
        techniques. While most people do not feel the need to encrypt most
        of their e-mails, it generally is a good idea to sign your e-mails.
        There are, for example, a lot of viruses these days that use other
        people's e-mail addresses in the From: field of viruses. If the
        people who you are communicating with know that you sign your e-mails,
        they will not open fake e-mail from viruses. Besides that it looks
        much more professional if people can check your identity, especially
        in business transactions. For example, who would you rather trust,
        vampire_boy93853@hotmail.com, or someone using a professional e-mail
        address with digitally signed e-mails?
      </p>
<p>
        This section describes how you can use GnuPG with mutt, for more
        information about GnuPG read
        <a class="xref" href="#basics-filesystem-gnupg" title="8.9. Encrypting and signing files">Section 8.9, “Encrypting and signing files”</a>.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-mutt-gnupg-configuration"></a>12.5.2. Configuration</h3></div></div></div>
<p>
        An example configuration for using GnuPG in mutt can be found
        in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/share/doc/mutt/samples/gpg.rc</code></html:span>.
        In general the contents of this file to your mutt configuration will
        suffice. From the shell you can add the contents of this file
        to your <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.muttrc</code></html:span> with the following command:
      </p>
<pre class="screen">
$ <span class="command"><strong>cat /usr/share/doc/mutt/samples/gpg.rc &gt;&gt; ~/.muttrc</strong></span>
      </pre>
<p>
        There are some handy parameters that you can additionally set.
        For example, if you always want to sign e-mails, add the following
        line to your mutt configuration:
      </p>
<pre class="screen">
set crypt_autosign = yes
      </pre>
<p>
        Another handy option is <span class="emphasis"><em>crypt_replyencrypt</em></span>,
        which will automatically encrypt replies to messages that were
        encrypted. To enable this, add the following line to your mutt
        configuration:
      </p>
<pre class="screen">
set crypt_replyencrypt = yes
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-mutt-gnupg-usage"></a>12.5.3. Usage</h3></div></div></div>
<p>
        If you have set some of the automatic options, like
        <span class="emphasis"><em>crypt_autosign</em></span>, GnuPG usage of mutt is mostly
        automatic. If not, you can press the &lt;p&gt; key during the
        final step of sending an e-mail. In the bottom of the screen
        various GnuPG/PGP options will appear, which you can access
        via the letters that are enclosed in parentheses. For example,
        &lt;s&gt; signs e-mails, and &lt;e&gt; encrypts an e-mail.
        You can always clear any GnuPG option you set by pressing
        &lt;p&gt; and then &lt;c&gt;.
      </p>
</div>
</div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="email-sendmail"></a>Chapter 13. Sendmail</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#email-sendmail-introduction">13.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#email-sendmail-installation">13.2. Installation</a></span></dt>
<dt><span class="sect1"><a href="#email-sendmail-configuration">13.3. Configuration</a></span></dt>
</dl>
</div>
<a class="indexterm" name="idm950624980"></a><div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="email-sendmail-introduction"></a>13.1. Introduction</h2></div></div></div>
<a class="indexterm" name="idm950624380"></a><a class="indexterm" name="idm950624172"></a><p>
      Sendmail is the default Mail Transfer Agent (<acronym class="acronym">MTA</acronym>)
      that Slackware Linux uses. sendmail was originally written by Eric
      Allman, who still maintains sendmail. The primary role of the sendmail
      MTA is delivering messages, either locally or remotely. Delivery
      is usually done through the SMTP protocol. This means that sendmail
      can accept e-mail from remote sites through the SMTP port, and that
      sendmail delivers mail destined for remote sites to other SMTP
      servers.
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="email-sendmail-installation"></a>13.2. Installation</h2></div></div></div>
<a class="indexterm" name="idm950622724"></a><p>
      Sendmail is available as the <span class="emphasis"><em>sendmail</em></span> package
      in the <span class="quote">“<span class="quote">n</span>”</span> disk set. If you want to generate your own
      sendmail configuration files, the <span class="emphasis"><em>sendmail-cf</em></span>
      package is also required. For information about how to install
      packages on Slackware Linux, refer to
      <a class="xref" href="#chap-pkgmgmt" title="Chapter 17. Gestió de paquets">Chapter 17, <i>Gestió de paquets</i></a>.
    </p>
<p>
      You can let Slackware Linux start sendmail during each boot by
      making the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.sendmail</code></html:span> executable.
      You can do this by executing:
    </p>
<pre class="screen">
# <span class="command"><strong>chmod a+x /etc/rc.d/rc.sendmail</strong></span>
    </pre>
<p>
      You can also start, stop and restart sendmail by using
      <span class="emphasis"><em>start</em></span>, <span class="emphasis"><em>stop</em></span>, and
      <span class="emphasis"><em>restart</em></span> as a parameter to the sendmail
      initialization script. For example, you can restart sendmail
      in the following way:
    </p>
<pre class="screen">
# <span class="command"><strong>/etc/rc.d/rc.sendmail restart</strong></span>
    </pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="email-sendmail-configuration"></a>13.3. Configuration</h2></div></div></div>
<p>
      The most central sendmail configuration file is
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/sendmail.cf</code></html:span>; this is where the 
      behavior of sendmail is configured, and where other files
      are included. The syntax of <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/sendmail.cf</code></html:span>
      is somewhat obscure, because this file is compiled from a
      much simpler <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.mc</code></html:span> files that uses M4 macros
      that are defined for sendmail.
    </p>
<p>
      Some definitions can easily be changed in the
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/sendmail.cf</code></html:span> file, but for other
      changes it is better to create your own <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.mc</code></html:span>
      file. Examples in this chapter will be focused on creating a
      customized mc file.
    </p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-sendmail-configuration-mc"></a>13.3.1. Working with mc files</h3></div></div></div>
<a class="indexterm" name="idm950615972"></a><p>
        In this section we will look how you can start off with an
        initial mc file, and how to compile your own .mc file to a
        cf file. There are many interesting example mc files available
        in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/share/sendmail/cf/cf</code></html:span>. The most
        interesting examples are <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">sendmail-slackware.mc</code></html:span>
        (which is used for generating the default Slackware Linux
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">sendmail.cf</code></html:span>), and
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">sendmail-slackware-tls.mc</code></html:span> which adds
        TLS support to the standard Slackware Linux sendmail configuration.
        If you want to create your own sendmail configuration, it is
        a good idea to start with a copy of the standard Slackware Linux
        mc file. For instance, suppose that we would like to create
        a configuration file for the server named <span class="emphasis"><em>straw</em></span>,
        we could execute:
      </p>
<pre class="screen">
# <span class="command"><strong>cd /usr/share/sendmail/cf/cf</strong></span>
# <span class="command"><strong>cp sendmail-slackware.mc sendmail-straw.mc</strong></span>
      </pre>
<p>
        and start editing <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">sendmail-straw.mc</code></html:span>. After
        the configuration file is modified to our tastes, M4 can be used
        to compile a cf file:
      </p>
<pre class="screen">
# <span class="command"><strong>m4 sendmail-straw.mc &gt; sendmail-straw.cf</strong></span>
      </pre>
<p>
        If we want to use this new configuration file as the default
        configuration, we can copy it to
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/sendmail.cf</code></html:span>:
      </p>
<pre class="screen">
# <span class="command"><strong>cp sendmail-straw.cf /etc/mail/sendmail.cf</strong></span>
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-sendmail-configuration-smarthost"></a>13.3.2. Using a smarthost</h3></div></div></div>
<a class="indexterm" name="idm950610876"></a><p>
        If you would like to use another host to deliver e-mail to
        locations to which the sendmail server you are configuring can not
        deliver you can set up sendmail to use a so-called <span class="quote">“<span class="quote">smart
        host</span>”</span>. Sendmail will send the undeliverable e-mail to the
        smart host, which is in turn supposed to handle the e-mail. You do
        this by defining <span class="emphasis"><em>SMART_HOST</em></span> in your mc file.
        For example, if you want to use <span class="emphasis"><em>smtp2.example.org</em></span>
        as the smart host, you can add the following line:
      </p>
<pre class="screen">
define(`SMART_HOST',`stmp2.example.org')
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-sendmail-configuration-accepthosts"></a>13.3.3. Alternative host/domain names</h3></div></div></div>
<a class="indexterm" name="idm950608668"></a><p>
        By default sendmail will accept mail destined for localhost, and the
        current hostname of the system. You can simply add additional hosts
        or domains to accept e-mail for. The first step is to make sure that 
        the following line is added to your mc configuration:
      </p>
<pre class="screen">
FEATURE(`use_cw_file')dnl
      </pre>
<p>
        When this option is enabled you can add host names and domain
        names to accept mail for to
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/local-host-names</code></html:span>. This file
        is a newline separated database of names. For example, the file
        could look like this:
      </p>
<pre class="screen">
example.org
mail.example.org
www.example.org
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="email-sendmail-configuration-mapaddr"></a>13.3.4. Virtual user table</h3></div></div></div>
<a class="indexterm" name="idm950606436"></a><p>
        Often you may want to map e-mail addresses to user names. This
        is needed when the user name differs from the part before the
        <span class="quote">“<span class="quote">@</span>”</span> part of an e-mail address. To enable this
        functionality, make sure the following line is added to your
        mc file:
      </p>
<pre class="screen">
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
      </pre>
<p>
        The mappings will now be read from
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/virtusertable.db</code></html:span>. This is a
        binary database file that should not directly edit. You can
        edit <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/virtusertable</code></html:span> instead,
        and generate <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/virtusertable.db</code></html:span>
        from that file.
      </p>
<p>
        The <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/mail/virtusertable</code></html:span> file is a simple
        plain text file. That has a mapping on each line, with an e-mail
        address and a user name separated by a tab. For example:
      </p>
<pre class="screen">
john.doe@example.org    john
john.doe@mail.example.org        john
      </pre>
<p>
        In this example both e-mail for
        <span class="emphasis"><em>john.doe@example.org</em></span> and
        <span class="emphasis"><em>john.doe@mail.example.org</em></span> will be
        delivered to the <span class="emphasis"><em>john</em></span> account. It is
        also possible to deliver some e-mail destined for a domain
        that is hosted on the server to another e-mail address,
        by specifying the e-mail address to deliver the e-mail to
        in the second column. For example:
      </p>
<pre class="screen">
john.doe@example.org    john.doe@example.com
      </pre>
<p>
        After making the necessary changes to the
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">virtusertable</code></html:span> file you can generate the
        database with the following command:
      </p>
<pre class="screen">
# <span class="command"><strong>makemap hash /etc/mail/virtusertable &lt; /etc/mail/virtusertable</strong></span>
      </pre>
</div>
</div>
</div>
  </div>

  <div class="part">
<div class="titlepage"><div><div><h1 class="title">
<a name="sysadmin"></a>Part V. Administració del sistema</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="chapter"><a href="#chap-usermgmt">14. Gestió d'usuaris </a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-usermgmt-intro">14.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-user">14.2. Afegint i suprimint usuaris</a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-su">14.3. Evitant l'ús de root mitjançant su </a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-quota">14.4. Cuota de disc</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#printing">15. Configuració de impressores </a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#printing-intro">15.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#printing-preparations">15.2. Preparatius </a></span></dt>
<dt><span class="sect1"><a href="#printing-configuration">15.3. Configuració</a></span></dt>
<dt><span class="sect1"><a href="#printing-accesscontrol">15.4. Control d'accés </a></span></dt>
<dt><span class="sect1"><a href="#printing-gspapersize">15.5. Tamany del paper Ghostscript </a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-x11">16. X11</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-x11-config">16.1. Configuració d'X</a></span></dt>
<dt><span class="sect1"><a href="#chap-x11-wm">16.2. Gestor de finestres </a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-pkgmgmt">17. Gestió de paquets</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-pkgmgmt-pkgtools">17.1. Pkgtools</a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-slackpkg">17.2. Slackpkg</a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-rsync">17.3. Obtenint actualitzacions mitjançant rsync 
    </a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-tagfiles">17.4. Tagfiles (fitxers d'etiquetes)</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#kernel">18. Contruïnt un núcli</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-kernel-intro">18.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-build">18.2. Configuració</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-compile">18.3. La compilació</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-install">18.4. Instal·lació</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#chap-init">19. System initialization</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#chap-init-lilo">19.1. The bootloader</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-init">19.2. init</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-initscripts">19.3. Initialization scripts</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-udev">19.4. Hotplugging and device node management</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-firmware">19.5. Device firmware</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#idm950258444">20. Security</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950258188">20.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950256916">20.2. Closing services</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#sysadmin-misc">21. Miscel·lània</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#sysadmin-misc-cron">21.1. Planificant tasques amb cron </a></span></dt>
<dt><span class="sect1"><a href="#sysadmin-misc-hdparm">21.2. Paràmetres de disc dur </a></span></dt>
<dt><span class="sect1"><a href="#sysadmin-memory-hdparm">21.3. Monitorejant  l'ús de la memòria </a></span></dt>
</dl></dd>
</dl>
</div>
    
    
    <div lang="en" class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-usermgmt"></a>Chapter 14. Gestió d'usuaris </h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-usermgmt-intro">14.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-user">14.2. Afegint i suprimint usuaris</a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-su">14.3. Evitant l'ús de root mitjançant su </a></span></dt>
<dt><span class="sect1"><a href="#chap-usermgmt-quota">14.4. Cuota de disc</a></span></dt>
</dl>
</div>
  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-usermgmt-intro"></a>14.1. Introducció</h2></div></div></div>
    

    <p>
      GNU/Linux és un sistema opertiu multi-usuari. Açò significa que
      múltiples usuaris poden utilitzar el sistema, i ho poden fer
      simultàniament. Els conceptes relatius a gestió d'usuaris del 
      GNU/Linux són bastant senzills. Primer que res, hi ha diversos
      comptes d'usuari en cada sistema. Inclús en un sistema d'un
      únic usuari hi múltiples comptes d'usuari perque GNU/Linux
      utilitza comptes especials per a algunes tasques. El usuaris
      poden pertanyer a grups. Els grups s'utilitzen per a augmentar
      la granularitat dels permisos, per exemple, pots fer un fitxer
      llegible per a cert grup. Hi ha uns quants usuaris i grups
      reservats a cada sistema, el més important dels quals és 
      <span class="emphasis"><em>root</em></span>. L'usuari <span class="emphasis"><em>root</em></span>
      és l'administrador del sistema. Es recomanable evitar 
      iniciar sessió, perque incrementa enormement els riscos de
      seguretat, en el seu lloc pots iniciar sessió com un usuari
      normal i realitzar les tasques d'administració del sistema
      utilitzant les ordres <span class="command"><strong>su</strong></span> i
      <span class="command"><strong>sudo</strong></span>.

      
    </p>

    <p>
      Els comptes d'usuari disponibles estàn especificats al fitxer
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/passwd</code></html:span>. Pots fer una ullada a este
      fitxer per a fer-te una idea de quins comptes d'usuari són
      obligatoris. Potser ja t'has adonat de que no hi ha
      contrasenyes en este fitxer. Les contrasenyes es mantenen
      a un fitxer separat, <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/shadow</code></html:span>, com
      cadenes xifrades. La informació relativa als grups s'emmagatzema
      al fitxer <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/group</code></html:span>. Per norma general
      no és bona idea modificar aquests fitxers directament, hi ha
      algunes eines excel·lents que poden ajudar-te amb
      l'administració de usuaris i groups. Aquest capítol en descriurà
      algunes.

      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-usermgmt-user"></a>14.2. Afegint i suprimint usuaris</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-user-add"></a>14.2.1. useradd</h3></div></div></div>
      

      <p>
	<span class="command"><strong>useradd</strong></span> s'utilitza per a afegir comptes d'usuari
	al sistema. Executant <span class="command"><strong>useradd</strong></span> amb un nom d'usuari
	com a paràmetre crearà l'usuari en el sistema. Per exemple:
	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>useradd jaume</code></strong>
      </pre>

      <p>
	Crea el compte d'usuari <span class="emphasis"><em>jaume</em></span>, Per favor
	tin en compte que açò no crea un directori llar per a l'usuari.
	Afegeix el paràmetre <em class="parameter"><code>-m</code></em>
	per a crear-lo. Per exemple:

	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>useradd -m jaume</code></strong>
      </pre>

      <p>
	Açò afegiria l'usuari <span class="emphasis"><em>jaume</em></span> al sistema, i
	crearia el directori llar <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home/jaume</code></html:span> per
	a este usuari. Normalment, l'usuari és fet membre del grup
	<span class="emphasis"><em>users</em></span>. Suposem que ens agradaria fer que
	<span class="emphasis"><em>crew</em></span> fora el grup primari de l'usuari
	<span class="emphasis"><em>jaume</em></span>. Açò es pot fer utilitzant el
	paràmetre <em class="parameter"><code>-g</code></em>. Per
	exemple:

	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>useradd -g crew -m jordi</code></strong>
      </pre>

      <p>
	Tmbé és possible afegir a este usuari a grups secundaris
	durant la creació del compte amb el paràmetre 
	<span class="emphasis"><em>-G</em></span>. Els noms de grup es poden separar
	amb una coma. La ordre següent crearia l'usuari
	<span class="emphasis"><em>bob</em></span>, que és un membre del grups
	<span class="emphasis"><em>crew</em></span> i dels grups seundaris
	<span class="emphasis"><em>www-admins</em></span> i <span class="emphasis"><em>ftp-admins</em></span>:

	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>useradd -g crew -G www-admins,ftp-admins -m jaume</code></strong>
      </pre>

      <p>
	Per defecte, <span class="command"><strong>useradd</strong></span> només afegeix usuaris,
	no defineix un password per a l'usuari afegit, aquesta tasca
	es fa mitjançant la ordre <span class="command"><strong>passwd</strong></span>.

	
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-user-passwd"></a>14.2.2. passwd</h3></div></div></div>
      

      <p>
	Com hauràs endevinat, la ordre <span class="command"><strong>passwd</strong></span> s'utilitza
	per a definir la contrasenya per a un usuari. Executant esta ordre
	amb un usuari com a paràmetre canviarà la contrasenya d'este usuari.
	La ordre <span class="command"><strong>passwd</strong></span> demanarà la contrasenya antiga
	una vegada i dos la nova:
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>passwd</code></strong>
Old password: 
Enter the new password (minimum of 5, maximum of 127 characters)
Please use a combination of upper and lower case letters and numbers.
New password: 
Re-enter new password: 
Password changed.
      </pre>

      <p>
	L'usuari <span class="emphasis"><em>root</em></span> pot definir contrasenyes per a
	usuaris especificant el nom d'usuari com a paràmetre. En este cas,
	la ordre <span class="command"><strong>passwd</strong></span> només demanarà la contrasenya nova.
	Per exemple:
	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>passwd jaume</code></strong>
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-user-adduser"></a>14.2.3. adduser</h3></div></div></div>
      

      <p>
	La ordre <span class="command"><strong>adduser</strong></span> combina les ordres
	<span class="command"><strong>useradd</strong></span> i <span class="command"><strong>passwd</strong></span> en un
	script interactiu. Et demanarà que introduisques la informació
	relativa al compte a crear i després d'això, crearà un compte
	basat en la informació proporcionada. A continuació es mostra
	un exemple de sessió. 

	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>adduser</code></strong>

Login name for new user []: <strong class="userinput"><code>jhon</code></strong>

User ID ('UID') [ defaults to next available ]: <strong class="userinput"><code>&lt;Enter&gt;</code></strong>

Initial group [ users ]: <strong class="userinput"><code>&lt;Enter&gt;</code></strong>

Additional groups (comma separated) []: <strong class="userinput"><code>staff</code></strong>

Home directory [ /home/jhon ] <strong class="userinput"><code>&lt;Enter&gt;</code></strong>

Shell [ /bin/bash ] <strong class="userinput"><code>&lt;Enter&gt;</code></strong>

Expiry date (YYYY-MM-DD) []: <strong class="userinput"><code>&lt;Enter&gt;</code></strong>

New account will be created as follows:

---------------------------------------
Login name.......:  jhon
UID..............:  [ Next available ]
Initial group....:  users
Additional groups:  [ None ]
Home directory...:  /home/jhon
Shell............:  /bin/bash
Expiry date......:  [ Never ]

This is it... if you want to bail out, hit Control-C.  Otherwise, press
ENTER to go ahead and make the account.
<strong class="userinput"><code>&lt;Enter&gt;</code></strong>

Creating new account...


Changing the user information for jhon
Enter the new value, or press ENTER for the default
        Full Name []: <strong class="userinput"><code>John Doe</code></strong>
        Room Number []: <strong class="userinput"><code>&lt;Enter&gt;</code></strong>
        Work Phone []: <strong class="userinput"><code>&lt;Enter&gt;</code></strong>
        Home Phone []: <strong class="userinput"><code>&lt;Enter&gt;</code></strong>
        Other []: <strong class="userinput"><code>&lt;Enter&gt;</code></strong>
Changing password for john
Enter the new password (minimum of 5, maximum of 127 characters)
Please use a combination of upper and lower case letters and numbers.
New password: <strong class="userinput"><code>password</code></strong>
Re-enter new password: <strong class="userinput"><code>password</code></strong>


Account setup complete.
      </pre>

      <p>
	Pots utilitzar els valos per defecte, o deixar alguns camps buits,
	donant-li un colpet a la tecla &lt;Enter&gt;
	
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-user-userdel"></a>14.2.4. userdel</h3></div></div></div>
      

      <p>
	De vegades és necessari eliminar un compte d'usuari del sistema.
	GNU/Linux ofereix la eina <span class="command"><strong>userdel</strong></span> per a fer açò.
	Senzillament especifica el nom d'usuari com a paràmetre per a 
	eliminar a eixe usuari del sistema. Per exemple, la següent ordre
	eliminarà el compte d'usuari <span class="emphasis"><em>jaume</em></span> del sistema:
	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>userdel jaume</code></strong>
      </pre>

      <p>
	Açò només elimina el compte d'usuari, no la carpeta llar de l'usuari
	ni el seu correu. Senzillament, afegeix el paràmetre  
	<em class="parameter"><code>-r</code></em> per a eliminar també
	la carpeta llar de l'usuari i el seu correu. Per exemple:
	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>userdel -r jaume</code></strong>
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-usermgmt-su"></a>14.3. Evitant l'ús de root mitjançant su </h2></div></div></div>
    

    <p>
      Evitar inicar sessió com a <span class="emphasis"><em>root</em></span> és una bona idea.
      Hi ha moltes raons per a no fer-ho, teclejar una ordre equivocada podria
      provocar que passaren coses dolentes i programes maliciosos poden fer molt
      de mal quan has iniciat sessió com a <span class="emphasis"><em>root</em></span>. Així i
      tot hi ha moltes situacions en què necessites tindre accés de root. Per
      exemple per a administrar el sistema o per a instal·lar programai nou.
      Afortunadament la ordre <span class="command"><strong>su</strong></span> pot donar-te temporalment
      privilegis de root.
      
      
    </p>

    <p>
      Utilitzar <span class="command"><strong>su</strong></span> és molt senzill, només executant
      <span class="command"><strong>su</strong></span> se't demanarà la contrassenya del root, una vegada
      ben introduïda, s'iniciarà un shell amb privilegis de root:

      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>whoami</code></strong>
jaume
$ <strong class="userinput"><code>su</code></strong>
Password: 
# <strong class="userinput"><code>whoami</code></strong>
root
# <strong class="userinput"><code>exit</code></strong>
exit
$ <strong class="userinput"><code>whoami</code></strong>
jaume
    </pre>

    <p>
      En aquest exemple, l'usuari <span class="emphasis"><em>bob</em></span> ha iniciat 
      sessió, la eixida de la ordre <span class="command"><strong>whoami</strong></span> així ho 
      reflecteix. L'usuari executa su i introdueix la contrasenya del
      root, aleshores <span class="command"><strong>su</strong></span> llança un shell amb
      privilegis de root, així ho confirma la eixida de la ordre 
      <span class="command"><strong>whoami</strong></span>. Despŕes d'eixir del shell de root,
      el retorna el control al shell en execució originalment amb els
      privilegis de l'usuari <span class="emphasis"><em>bob</em></span>.

      
    </p>

    <p>
      També és possible executar només una ordre com a l'usuari
      <span class="emphasis"><em>root</em></span> mitjançant el paràmetre 
      <em class="parameter"><code>-c</code></em>- El següent exemple
      executarà el <span class="command"><strong>lilo</strong></span>:
      
    </p>

    <pre class="screen">
$ <strong class="userinput"><code>su -c lilo</code></strong>
    </pre>

    <p>
      Si volguéres passar-li paràmteres a la ordre que t'agradaria executar,
      utilitza cometes (p. ex. <span class="command"><strong>su -c "ls -l /"</strong></span>).
      Sense cometes la ordre <span class="command"><strong>su</strong></span> no pot determinar si els
      paràmetres s'ha d'utilitzar per la ordre especificada o pel mateix
      <span class="command"><strong>su</strong></span>.

      
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-su-restrict"></a>14.3.1. Restingint l'accés de su </h3></div></div></div>
      

      <p>
	Pots afinar l'accés a <span class="command"><strong>su</strong></span> amb 
	<span class="emphasis"><em>suauth</em></span>. És una bon hàbit de seguretat només
	permetre als usuaris d'un grup especial utilitzar <span class="command"><strong>su</strong></span>
	per a fer-se passar per <span class="emphasis"><em>root</em></span>. Per exemple,
	pots restringir l'ús de	<span class="command"><strong>su</strong></span> per a fer-se passar per
	root als membres del grup <span class="emphasis"><em>wheel</em></span>, a l'estil BSD,
	afegint la següent línia a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/suauth</code></html:span>:

	
      </p>

      <pre class="screen">
root:ALL EXCEPT GROUP wheel:DENY
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-usermgmt-quota"></a>14.4. Cuota de disc</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-quota-intro"></a>14.4.1. Introducció</h3></div></div></div>
      

      <p>
	La cuota de disc és un mecanisme que permet a l'administrador
	restingir el nombre de blocs de disc i inodes que un usuari
	i grup particulars poden utilitzar. No tots els sistemes de
	fitxers suportats pel Linux ofereixen suport per a cutoes de
	????disc. Alguns sistemes amplament utilitzats que suporten cuotes
	de disc só ext2, ext3 i XFS. Les cuotes s'activen i es gestionen
	per a cada sistema de fitxers.????
	
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-config"></a>14.4.2. Habilitant cuotes </h3></div></div></div>
      

      <p>
	Les cuotes es poden habilitar per sistemes de fitxers a 
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/fstab</code></html:span>, mitjançant les opcions
	de sistema de fitxers <em class="parameter"><code>usrquota</code></em> i
	<em class="parameter"><code>grpquota</code></em>. Per exemple, suposa que
	tenim la següent entrada per a la partició 
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home</code></html:span> a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/fstab</code></html:span>:

	
      </p>

      <pre class="screen">
/dev/hda8        /home            xfs         defaults         1   2
      </pre>

      <p>
	Ara podem habilitar la cuota afegint le opció
	de sistema de fitxers <em class="parameter"><code>usrquota</code></em>:

	
      </p>

      <pre class="screen">
/dev/hda8        /home            xfs         defaults<span class="bold"><strong>,usrquota</strong></span> 1   2
      </pre>

      <p>
	En aquest punt podem reiniciar la màquina, per a permetre
	als guions d'inicialització de Slackware Linux habilitar les
	cuotes. També es pot habilitar les cuotes sense reiniciar la
	máquina, remuntant la partició, i executant la ordre
	<span class="command"><strong>quotaon</strong></span>:

	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>mount -o remount /home</code></strong>
# <strong class="userinput"><code>quotaon -avug</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-quota-edit"></a>14.4.3. Editant cuotes </h3></div></div></div>
      

      <p>
	Les cuotes de grup i de usuari es poden editar amb
	la utilitat <span class="quote">“<span class="quote">edquota</span>”</span>. Este programar
	permet editar cuotes interactivament amb l'editor
	vi. La sintaxi més bàsica d'aquesta ordre és
	<span class="command"><strong>edquota username</strong></span>. Per exemple:

	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>edquota joe</code></strong>
      </pre>

      <p>
	Açò llançarà l'editor <span class="command"><strong>vi</strong></span> amb la
	informació de la cuota per a l'usuari <span class="emphasis"><em>joe</em></span>.
	S'asemblarà a açò:
	
	
      </p>

      <pre class="screen">
Disk quotas for user joe (uid 1143):
  Filesystem                   blocks       soft       hard     inodes     soft    hard
  /dev/hda5                      2136          0          0         64        0       0
      </pre>

      <p>
	En este exemple, les cuotes estàn habilitades per a un sistema
	de fitxers només, el que resideix a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hda5</code></html:span>.
	Com es pot vore, hi ha vàries columnes. La columna <span class="emphasis"><em>blocks
	</em></span> mostra quants blocs utilitza l'usuari al sistema
	de fitxers, i la columna <span class="emphasis"><em>inodes</em></span> el nombre
	d'inodes ocupats per l'usuari. A més d'això, hi ha les columnes
	<span class="emphasis"><em>soft</em></span>(tou) and <span class="emphasis"><em>hard</em></span>(dur) 
	després de <span class="emphasis"><em>blocks</em></span> i
	<span class="emphasis"><em>inodes</em></span>. Aquestes columnes especifiquen el
	límit tou i el dur a blocs i inodes. Un usuari pot excedir el
	límit tou durant un període de gràcia, però l'usuari no podrà
	mai excedir el límit dur. Si el valor d'un límit és 
	<span class="emphasis"><em>0</em></span>, això és que no n'hi ha.
	

	
      </p>

      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
	<p>
	  El terme <span class="quote">“<span class="quote">blocs</span>”</span> podria ser una miquet confús en
	  este context. En els paràmetres de cuota un bloc és 1KB, no
	  el tamany de bloc del sistema de fitxers.

          
        </p>
      </td></tr>
</table></div>

      <p>
	Vejam un exemple senzill. Suposem que ens agradaria posar el 
	límit tou per a l'usuari <span class="emphasis"><em>joe</em></span> a 
	<span class="emphasis"><em>250000</em></span>, i límit dur a
	<span class="emphasis"><em>300000</em></span>. Nosaltre podríem canviar les
	cuotes llistades més amunt a:

	
      </p>

      <pre class="screen">
Disk quotas for user joe (uid 1143):
  Filesystem                   blocks       soft       hard     inodes     soft    hard
  /dev/hda5                      2136     <span class="bold"><strong>250000</strong></span>     <span class="bold"><strong>300000</strong></span>         64        0       0
      </pre>

      <p>
	Els nous paràmetres de la cuota d'este usuari estarán actius
	després d'alár el fitxer, i llevar el <span class="command"><strong>vi</strong></span>.
        
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-usermgmt-quota-repquota"></a>14.4.4. Obtenint informació relativa a la cuota </h3></div></div></div>
      

      <p> 
	Sol ser útil obtindre estadístiques relatives a l'ús actual 
	de la cuota. La ordre <span class="command"><strong>repquota</strong></span> es pot
	utilitzar per a obtindre informació de quines cuotes estan
	fixades per a cada usuari, i quina quantitat d'aquestes està
	en ús. Es poden veurer els paràmetres de cuota per a una
	partició especificada passant-li el nom de la partició com a
	paràmetre i el paràmetre <em class="parameter"><code>-a</code></em>
	mostrarà la informació de cuota de totes les particions amb
	la cuota habilitada. Suposa que t'agradaria veurer la informació 
	de cuota per a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hda5</code></html:span>, pots utilitzar
	la ordre següent:

	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>repquota /dev/hda5</code></strong>
*** Report for user quotas on device /dev/hda5
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --       0       0       0              3     0     0       
[..]
joe       --    2136  250000  300000             64     0     0       
[..]
      </pre>
    </div>
  </div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="printing"></a>Chapter 15. Configuració de impressores </h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#printing-intro">15.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#printing-preparations">15.2. Preparatius </a></span></dt>
<dt><span class="sect1"><a href="#printing-configuration">15.3. Configuració</a></span></dt>
<dt><span class="sect1"><a href="#printing-accesscontrol">15.4. Control d'accés </a></span></dt>
<dt><span class="sect1"><a href="#printing-gspapersize">15.5. Tamany del paper Ghostscript </a></span></dt>
</dl>
</div>
<a class="indexterm" name="idm950527652"></a><div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="printing-intro"></a>15.1. Introducció</h2></div></div></div>
<a class="indexterm" name="idm950526972"></a><p>
      GNU/Linux suporta una enorme porció de les impressores USB, paral·lel i 
      de xarxa disponibles. Slackware Linux proporciona dos sistemes d'impressió,
      <acronym class="acronym">CUPS</acronym> (Common UNIX Printing System, Sistema comú de Impressió
      de UNIX) i <acronym class="acronym">LPRNG</acronym> (LPR Next Generation, LPR de pròxima 
      generació). Aquest capítol cobreix el sistema CUPS.

      
    </p>
<p>
      Independentment del sistema d'impressió que vages a utilitzar, és
      una bona idea instal·lar alguna col·lecció de filtres d'impressora.
      Aquests es poden trobar al conjunt de disc <span class="quote">“<span class="quote">ap</span>”</span>. Si
      vols tindre suport per a la majoria d'impressores, assagura't de
      que els següents paquets estàn instal·lats.
      
    </p>
<pre class="screen">
a2ps
enscript
espgs
gimp-print
gnu-gs-fonts
hpijs
ifhp
    </pre>
<p>
      Ambdós sistemes d'impressió tenen els seus propis avantatges i 
      inconvenients. Si no tens massa experiència configurant impressores baix 
      GNU/Linux, és una bona idea utilitzar CUPS, ja que CUPS proporciona una 
      còmoda interfície web accessible mitjançant un navegador web.
      
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="printing-preparations"></a>15.2. Preparatius </h2></div></div></div>
<a class="indexterm" name="idm950522652"></a><p>
      Per a poder utilitzar CUPS, el paquet <span class="quote">“<span class="quote">cups</span>”</span> del conjunt
      de disc <span class="quote">“<span class="quote">a</span>”</span> ha d'estar instal·lat. Després de la instal·lació
      CUPS es pot iniciar automàticament durant cada llançament del sistema fent
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.cups</code></html:span> executable, el que es pot fer amb la
      ordre següent:
      
      
    </p>
<pre class="screen">
# <span class="command"><strong>chmod a+x /etc/rc.d/rc.cups</strong></span>
    </pre>
<p>
      Després de reiniciar el sistema, CUPS serà també reiniciat automàticament.
      Es pot iniciar CUPS a un sistema en marxa executant la següent ordre:
      
    </p>
<pre class="screen">
# <span class="command"><strong>/etc/rc.d/rc.cups start</strong></span>
    </pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="printing-configuration"></a>15.3. Configuració</h2></div></div></div>
<a class="indexterm" name="idm950519012"></a><p>
      CUPS es pot configurar mitjançant una interfície web a la que es pot 
      accedir amb un navegador web a la següent URL:
      <a class="ulink" href="http://localhost:631/" target="_top">http://localhost:631/</a>.
      Algunes parts de la interfície web requereixen que t'autentiques. Si 
      apareix una finestra d'autenticació pots introduir <span class="quote">“<span class="quote">root</span>”</span>
      com a nom d'usuari, i omplir la contrassenya del compte root.

      
    </p>
<p>
      Es pot afegir una impressora a la configuració de CUPS fent clic en
      <span class="quote">“<span class="quote">Administrate</span>”</span>, i a continuació, fent clic en el botó 
      <span class="quote">“<span class="quote">Add Printer</span>”</span>. La intefície web preguntarà per tres 
      opcions:
      
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
	  <span class="emphasis"><em>Nom</em></span> - el nom de la impressora. Utilitza un 
	  nom senzill, per exemple <span class="quote">“<span class="quote">epson</span>”</span>.
          
        </p></li>
<li class="listitem"><p>
	  <span class="emphasis"><em>Localització</em></span> - la localització física de la 
	  impressora. Aquest paràmetre no és crucial, però pràctic per a 
	  grans organitzacions.
          
        </p></li>
<li class="listitem"><p>
	  <span class="emphasis"><em>Description</em></span> - una descripció de la impressora,
	  per exemple <span class="quote">“<span class="quote">Epson Stylus Color C42UX</span>”</span>.
          
        </p></li>
</ul></div>
<p>
      Pots procedir fent clic al botó <span class="quote">“<span class="quote">Continue</span>”</span>. A la pàgina
      següent pots configurar com està connectada la impressora. Si tens 
      una impressora USB i està encesa, la interfície web mostrarà el nom
      de la impressora junt al port USB utilitzat. Després de configurar
      el port de la impressora, pots triar-ne la marca i el model. Després
      d'això la configuració de la impressora haurà acabat, i aquesta
      serà afegida a la configuració de CUPS.
      
    </p>
<p>
      Una visió del conjunt d'impressores configurades es pot trobar
      a la plana <span class="quote">“<span class="quote">Printers</span>”</span>. En aquesta plana pots, a més,
      fer algunes operaciones d'impressora. Per exemple, <span class="quote">“<span class="quote">Print 
      Test Page</span>”</span> es pot utilitzar per a comprovar la configuració
      d'una impressora imprimint una pàgina de prova.
      
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="printing-accesscontrol"></a>15.4. Control d'accés </h2></div></div></div>
<a class="indexterm" name="idm950509780"></a><p>
      El sistema d'impressió CUPS proporciona una interfície de configuració
      web, i accés a impressió remota mitjançant el Protocol d'Impressió
      d'Internet (<acronym class="acronym">IPP</acronym>, Internet Printing Protocol). Els
      fitxers de configuració de CUPS et permeten una configuració molt fina
      del control d'accés a les impressores. L'accés per defecte a impressores
      està limitat a <span class="emphasis"><em>localhost</em></span> (<span class="emphasis"><em>127.0.0.1</em></span>).

      
    </p>
<p>
      Es pot refinar el contol d'accés al fitxer de configuració del dimoni
      central de CUPS, <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/cups/cupsd.conf</code></html:span>, que té una
      sintaxi comparable a la del fitxer de configuració d'Apache. El control
      d'accés es configura mitjançant seccions <span class="emphasis"><em>Location</em></span>.
      Per exemple, la secció global per defecte (el directori arrel d'IPP) 
      es pareix a açò:
      
    </p>
<pre class="screen">
&lt;Location /&gt;
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
&lt;/Location&gt;
    </pre>
<p>
      Com pots veurer les sentències deny es manejen primer, a continuació 
      les allow. En la configuració per defecte, l'accés és denegat desde 
      tots els hosts, excepte per a <span class="emphasis"><em>127.0.0.1</em></span>, 
      <span class="emphasis"><em>localhost</em></span>. Ara suposa que t'agradaria permetre
      als ordinadors de la xarxa local, que utilitzen l'espai d'adreçament
      <span class="emphasis"><em>192.168.1.0/24</em></span>, utilitzar les impressores al
      sistema on estàs configurant el CUPS. En este cas podries afegir
      la línia que està en negreta:
      
    </p>
<pre class="screen">
&lt;Location /&gt;
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
<span class="bold"><strong>Allow From 192.168.1.0/24</strong></span>
&lt;/Location&gt;
    </pre>
<p>
      Pots refinar altres localitzacions en l'espai d'adreçament, afegint
      seccions location addicionals. Les configuracions per a subdirectoris
      sobreescriuen les globals. Per exemple, podries restringir l'accés a 
      la impressora <span class="emphasis"><em>epson</em></span> als hosts amb adreces IP 
      <span class="emphasis"><em>127.0.0.1</em></span> i <span class="emphasis"><em>192.168.1.203</em></span>
      afegint la secció següent:

      
    </p>
<pre class="screen">
&lt;Location /printers/epson&gt;
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
Allow From 192.168.1.203
&lt;/Location&gt;
    </pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="printing-gspapersize"></a>15.5. Tamany del paper Ghostscript </h2></div></div></div>
<a class="indexterm" name="idm950501116"></a><p>
      Ghostscript és un intèrpret PostScript i (<acronym class="acronym">PDF</acronym>) 
      (Portable Document Format, format portable de documents). Tant
      el PostScript com el PDF són llenguatges que descriuen dades
      que es poden imprimir. GhostScript s'utilitza per convertir 
      PostScript i PDF a un format de trama que es pot mostrar per 
      pantalla o imprimir. La majoria de programes de UNIX són capaços
      d'enviar a la eixida PostScript, mentres que la cua d'impressió 
      de CUPS utilitza GhostScript per a convertir este PostScript al 
      format de trama que una impressora en particular entén.

      
    </p>
<p>
      Hi ha alguns paràmetres de configuració de GhostScript que pot
      resultar d'utilitat canviar en algunes situacions. Aquesta secció
      descriu com pots canviar el tamany de paper que GhostScript 
      utilitza per defecte.
      
    </p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
	ALgunes impressores de gamma alta poden interpretar PostScript
	directament. Convertir a format de trama no és necessari per 
	aquestes impressores.
        
      </p></td></tr>
</table></div>
<p>
      Per defecte GhostScript utilitza el paper US letter com a tamany
      per defecte. El tamany del paper es configura a 
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/share/ghostscript/x.xx/lib/gs_init.ps</code></html:span>,
      on <span class="emphasis"><em>x.xx</em></span> s'hauria de substituir per el
      número de versió de GhostScript. No molt lluny del començament del
      fitxer hi ha dos línies que comentades amb un signe de percent (%),
      que s'assemblen a açò:
      
    </p>
<pre class="screen">
% Optionally choose a default paper size other than U.S. letter.
% (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
    </pre>
<p>
      Pots canviar la configuració de GhostScript per a que utilitze
      A4 com a tamany de paper per defecte esborrant el signe de percent
      i l'espai a l'inici de la segona línia, canviant-ho a:
      
    </p>
<pre class="screen">
% Optionally choose a default paper size other than U.S. letter.
(a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
    </pre>
<p>
      També és possible utilitzar un altre tamany de paper a banda
      de letter o A4 reemplaçant <span class="emphasis"><em>a4</em></span> a l'exemple
      de dalt amb el tamany de paper que tú utilitzes. Per exemple,
      pots definir el tamany de paper per defecte a US Legal amb:
      
    </p>
<pre class="screen">
% Optionally choose a default paper size other than U.S. letter.
(legal) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
    </pre>
<p>
      També es possible definir el tamany del paper en cada invocació de
      GhostScript utilitzant el paràmetre
      <em class="parameter"><code>-sPAPERSIZE=size</code></em> de la 
      ordre <span class="command"><strong>gs</strong></span>. Per exemple, pots afegir el paràmetre
      <span class="emphasis"><em>-sPAPERSIZE=a4</em></span> quan inicies 
      <span class="command"><strong>gs</strong></span> per a utilitzar A4 com el tamany de paper
      per a una invocació de GhostScript.

      
    </p>
<p>
      Un visió de conjunt del tamanys de paper suportat es pot
      trobar al fitxer <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">gs_statd.ps</code></html:span>, que es pot
      trobar en el mateix directori que <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">gs_init.ps</code></html:span>.
      
    </p>
</div>
</div>
    <div lang="en" class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-x11"></a>Chapter 16. X11</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-x11-config">16.1. Configuració d'X</a></span></dt>
<dt><span class="sect1"><a href="#chap-x11-wm">16.2. Gestor de finestres </a></span></dt>
</dl>
</div>
  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-x11-config"></a>16.1. Configuració d'X</h2></div></div></div>
    

    <p>
      La configuració d'X11 s'emmagatzema a 
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/X11/xorg.conf</code></html:span>. La majoria de 
      distribuciones proporcionen eines especials de configuració per
      a X, però Slackware Linux només proporciona les eines X11 estàndard
      (que de fet són molt fàcils d'utilitzar). En la majoria de casos X
      es pot configurar automàticament, per de vegades és necessari editar 
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/X11/xorg.conf</code></html:span> manualment.
      
      
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-x11-config-automatic"></a>16.1.1. Configuració automàtica </h3></div></div></div>
      

      <p>
	El servidor X11 proporciona una opción per a generar
	automàticamnet un fitxer de configuració. X11 carregarà tots els
	mòduls de drivers disponibles, i tractarà de detectar el maquinari,
	i generar un fitxer de configuració. Executa la ordre següent
	per a generar un fixer <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">xorg.conf</code></html:span> de 
	configuració:
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>X -configure</code></strong>
      </pre>

      <p>
	Si X no mostra cap error, la configuració generada pot ser
	copiada al directori <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/X11</code></html:span>, i X pot
	ser iniciat per a provar la configuració:
	
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>cp /root/xorg.conf /etc/X11/</code></strong>
$ <strong class="userinput"><code>startx</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-x11-config-interactive"></a>16.1.2. Configuració interactiva </h3></div></div></div>
      

      <p>
	X11 proporciona dos eines per a configurar X interactivament,
	<span class="command"><strong>xorgcfg</strong></span> i <span class="command"><strong>xorgconfig</strong></span>.
	<span class="command"><strong>xorgcfg</strong></span> intenta detectar la tarjeta de vídeo
	automàticament, i inicia una eina que pot ser utilitzada per a
	afinar la configuració. De vegades, <span class="command"><strong>xorgcfg</strong></span>
	canvia a un mode de vídeo que no està suportat pel monitor.
	En eixe cas <span class="command"><strong>xorgcfg</strong></span> es pot utilitzar també
	en mode text, inciant-la amb <span class="command"><strong>xorgcfg -textmode</strong></span>.

	
      </p>

      <p>
	<span class="command"><strong>xorgconfig</strong></span> es diferencia de les eines 
	descrites dalt, aquesta no detecta el maquinari i fara preguntes
	detallades referents al teu maquinari. Si tens poca experiència
	configurant X11 és una bona idea evitar 
	<span class="command"><strong>xorgconfig</strong></span>.
	
	
      </p>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-x11-wm"></a>16.2. Gestor de finestres </h2></div></div></div>
    

    <p>
      El <span class="quote">“<span class="quote">look and feel</span>”</span> de X11 és gestionat per
      un dels anoments gestor de finestres. Slacware Linux
      proporciona els següents amplament-utilitzats gestors de
      finestres.
      
    </p>

    <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	<p>
	  WindowMaker: Un gestor de finestres relativament lleuger,
	  que forma part del projecte GNUStep.
	  
	</p>
      </li>
<li class="listitem">
	<p>
	  BlackBox: Gestor de finestres lleuger, BlackBox no té 
	  dependències més enllà de les llibreries X11.
	  
	</p>
      </li>
<li class="listitem">
	<p>
	  KDE: Un entorn d'escriptori complet, incloent navegador,
	  porgrama de correu electrònic i una suite ofimàtica (KOffice)
	  
	</p>
      </li>
<li class="listitem">
	<p>
	  Xfce: Un entorn d'escriptori lleuger. Aquest és un entorn 
	  ideal si vols tindre un escriptori amigable que corre en 
	  màquines menys capaces.
	  
	</p>
      </li>
</ul></div>

    <p>
      Si estàs acostumat a un entorn d'escriptori, utilitzar KDE o Xfce
      és una tria lògica. Però és una bona idea provar alguns dels 
      gestors de finestres més lleugers. Són més ràpids, i consumeixen 
      menys memòria a pesar de que la majoria d'aplicacions KDE i Xfce
      són perfectament usables baix altres gestors de finestres.
      
    </p>

    <p>
      A Slackware Linux la ordre <span class="command"><strong>xwmconfig</strong></span> pot 
      utilitzar-se per a definir el gestor de finestres per defecte.
      Aquest programa mostra els gestors de finestres instal·lats, 
      dels què en pots triar un. Pots definir el gestor de finestres
      per defecte globalment executant <span class="command"><strong>xwmconfig</strong></span>
      com a root.
      
    </p>
  </div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-pkgmgmt"></a>Chapter 17. Gestió de paquets</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-pkgmgmt-pkgtools">17.1. Pkgtools</a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-slackpkg">17.2. Slackpkg</a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-rsync">17.3. Obtenint actualitzacions mitjançant rsync 
    </a></span></dt>
<dt><span class="sect1"><a href="#chap-pkgmgmt-tagfiles">17.4. Tagfiles (fitxers d'etiquetes)</a></span></dt>
</dl>
</div>
  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-pkgmgmt-pkgtools"></a>17.1. Pkgtools</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-pkgtools-intro"></a>17.1.1. Introducció</h3></div></div></div>
      

      <p>
	Slackware Linux no utilitza un complicat sistema de paquets
	com fan altres distribucions de Linux. Cada paquet té la 
	extensió <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.tgz</code></html:span>, i solen ser tarballs ordinàris
	que contenen dos fitxers extra: un guió d'instal·lació i un 
	fitxer de descripció del paquet. Degut a la senzillesa dels
	paquets, els ferraments de control de paquets de Slackware Linux
	no tenen manera de manejar dependències, però molts usuaris de
	Slackware Linux prefereixen aquest enfocament, perque les 
	dependències sovint provoquen més problemes dels que resolen.
	
      </p>

      <p>
	Slackware Linux té unes quantes eines per a manejar paquets.
	Les més importants es cobriràn en aquest capítol. Per a aprendre
	a entendre-les haurem d'analitzar els noms de paquet. 
	Vegem-ho amb un exemple, imaginem que tenim un paquet amb el nom 
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">bash-2.05b-i386-2.tgz</code></html:span>, en el nom del paquet 
	la informació referent al mateix està separada pel caràtcter '-' 
	i el seu significat és el següent:
	<span class="emphasis"><em>nomdelprograma-versió-arquitectura-revisiodelpaquet</em></span>
	
        
      </p>

    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-pkgtools-pkgtool"></a>17.1.2. pkgtool</h3></div></div></div>
      

      <p>
	La ordre <span class="command"><strong>pkgtool</strong></span> proporciona una interfície de menús
	per a algunes de les operacions sobre paquets. Els elements més
	importants són <span class="emphasis"><em>Remove</em></span> (eliminar) i  
	<span class="emphasis"><em>Setup</em></span> (instal·lar). La primera opció presenta una 
	llista de paquets instal·lats. Es pot sel·leccionar quins paquets es volen
	eliminar amb la barra d'espai i confirmar-ho amb la tecla de retorn.
	A més, pots desmarcar un paquet marcat per esborrar amb la barra d'espai.

	
      </p>

      <p>
	La opció <span class="emphasis"><em>Setup</em></span> dóna acces a unes poques eines
	que poden ajudar amb la configuració del sistema, per exemple:
	<span class="command"><strong>netconfig</strong></span>,<span class="command"><strong>pppconfig</strong></span> i 
	<span class="command"><strong>xwmconfig</strong></span>.

	
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-pkgtools-installpkg"></a>17.1.3. installpkg</h3></div></div></div>
      

      <p>
	El comandament <span class="command"><strong>installpkg</strong></span> s'utilitza per a 
	instal·lar paquets. <span class="command"><strong>installpkg</strong></span> necessita el 
	nom d'un fitxer de paquet com a paràmetre. Per exemple, si 
	volguéssim instal·lar el paquet <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">bash-2.05b-i386-2.tgz</code></html:span>.
	executariem:
	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>installpkg bash-2.05b-i386-2.tgz</code></strong>
      </pre>

    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-pkgtools-upgradepkg"></a>17.1.4. upgradepkg</h3></div></div></div>
      

      <p>
	<span class="command"><strong>upgradepkg</strong></span> es pot utilitzar per a actualitzar
	paquets. A diferència d'<span class="command"><strong>installpkg</strong></span>, només 
	instal·la paquets dels quals hi haja una versió més antiga 
	disponible al sistema. La sintaxi de l'orde és similar a la de
	<span class="command"><strong>installpkg</strong></span>. Per exemple, si volguéssim actualitzar
	paquets utilitzant paquets en un directori, executariem:

        
      </p>

      <pre class="screen">
# <strong class="userinput"><code>upgradepkg *.tgz</code></strong>
      </pre>

      <p>
	Com ja em dit, s'instal·laran només aquells paquets dels quals
	hi haja una versió meś vella ja instal·lada en el sistema.
        
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-pkgtools-removepkg"></a>17.1.5. removepkg</h3></div></div></div>
      

      <p>
	La ordre <span class="command"><strong>removepkg</strong></span> es pot utilitzar per a
	eliminar paquets instal·lats. Si, per exemple, volguerem
	eliminar el paquet <span class="quote">“<span class="quote">bash</span>”</span> (el que no és gens
	recomanable!), podríem executar:
	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>removepkg bash</code></strong>
      </pre>

      <p>
	Com es pot veurer només s'especifica el nom del programa en
	este exemple, obviament, també es pot eliminar un paquet 
	especificant el seu nom complet:
        
      </p>

      <pre class="screen">
# <strong class="userinput"><code>removepkg bash-2.05b-i386-2</code></strong>
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-pkgmgmt-slackpkg"></a>17.2. Slackpkg</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-slackpkg-intro"></a>17.2.1. Introducció</h3></div></div></div>
      

      <p>
	Slackpkg és una eina escrit per Robert F. Batista i Evaldo
	Gardenali. Aquesta eina ajudar als usuaris a instal·lar i actulitzar paquets
	de de Slackware Linux utilitzant un dels espills de la distribució.
	Slackpkg està inclòs en el directori <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">extra/</code></html:span>
	en el segon CD del conjunt de CD's de Slackware Linux.

        
      </p>

    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-slackpkg-config"></a>17.2.2. Configuració</h3></div></div></div>
      

      <p>
	Slackpkg es configura mitjançant alguns fitxers a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">
	/etc/slackpkg</code></html:span>. La primera cosa que hi ha que
	configurar és quin espill hauria de utilitzar slackpkg. Açò 
	es pot fer editant el fitxer <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/slackpkg/mirrors</code></html:span>.
	Este fitxer ja conté una llista d'espills, només hi ha que llevar
	el comentari d'un espill proper a tú.
               
        
      </p>

      <pre class="screen">
ftp://ftp.nluug.nl/pub/os/Linux/distr/slackware/slackware-12.0/
      </pre>

      <p>
	Açò utilitzarà l'arbre Slackware Linux 12.0 de l'espill
	ftp.nluug.nl. Assabenta't de utilitzar un arbre que es coresponga
	amb la teua versió. Per una altra banda, si volgueres seguir la 
	slackware-current hauries de llevar el comentari de la 
	línea següent (en cas de que volgueres utilitzar l'espill NLUUG):

        
      </p>

      <pre class="screen">
ftp://ftp.nluug.nl/pub/os/Linux/distr/slackware/slackware-current/
      </pre>

      <p>
	Slackpkg només acceptarà un espill, si se'n descomenten més
	no funcionarà.
        
      </p>

    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-slackpkg-gpgkey"></a>17.2.3. Importar la clau GPG de Slackware Linux</h3></div></div></div>
      

      <p>
	Per defecte, slackpkg comprova els paquets emprant les 
	seues signatures i la clau pública GPG de Slackware. Açò 
	és una bona idea des del punt de vista de la seguretat, 
	pel que probablement no vulgues canviar este comportament.
	Per a poder verificar paquets necessitaràs importar la clau
	GPG de <span class="emphasis"><em>security@slackware.com</em></span>. Si no
	has utilitzat mai GPG hauaràs de crear el directori GPG
	a la carpeta llar de l'usuari <span class="emphasis"><em>root</em></span>.

	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>mkdir ~/.gnupg</code></strong>
      </pre>

      <p>
	El pas següent és buscar la clau pública de 
	<span class="emphasis"><em>security@slackware.com</em></span>. Farem açò
	demanant-li al servidor <span class="emphasis"><em>pgp.mit.edu</em></span>:

        
      </p>

      <pre class="screen">
# <strong class="userinput"><code>gpg --keyserver pgp.mit.edu --search security@slackware.com</code></strong>
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: searching for "security@slackware.com" from HKP server pgp.mit.edu
Keys 1-2 of 2 for "security@slackware.com"
(1)     Slackware Linux Project &lt;security@slackware.com&gt;
          1024 bit DSA key 40102233, created 2003-02-25
(2)     Slackware Linux Project &lt;security@slackware.com&gt;
          1024 bit DSA key 40102233, created 2003-02-25
Enter number(s), N)ext, or Q)uit &gt; 
      </pre>

      <p>
	Com es pot veurer tenim dues coincidències (idèntiques). Seleccionem
	la primera introduint <span class="quote">“<span class="quote">1</span>”</span>. GnuPG importarà aquesta
	clau en l'anell de claus de l'usuari root:

        
      </p>

      <pre class="screen">
Enter number(s), N)ext, or Q)uit &gt; <strong class="userinput"><code>1</code></strong>
gpg: key 40102233: duplicated user ID detected - merged
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 40102233: public key "Slackware Linux Project &lt;security@slackware.com&gt;" imported
gpg: Total number processed: 1
gpg:               imported: 1
      </pre>

      <p>
	Assabenta't de comprobar per partida doble la clau rebuda. La 
	ID de la clau i la empremta dactilar d'esta clau en particular
	es poden trobar a la Internet en molts llocs confiables. El ID de 
	la clau, com s'ha mencionat adés, és<span class="emphasis"><em>40102233</em></span> i
	es pot obtindre la empremta de la clau amb el paràmetre 
	<em class="parameter"><code>--fingerprint</code></em>:
	
        
      </p>

      <pre class="screen">
# <strong class="userinput"><code>gpg --fingerprint security@slackware.com</code></strong>
pub  1024D/40102233 2003-02-26 Slackware Linux Project &lt;security@slackware.com&gt;
     Key fingerprint = EC56 49DA 401E 22AB FA67  36EF 6A44 63C0 4010 2233
sub  1024g/4E523569 2003-02-26 [expires: 2012-12-21]
      </pre>

      <p>
	Una vegada que hages importat i comprovat esta clau, es pot
	començar a utilitzar slackpkg i instal·lar paquets de forma
	segura.
        
      </p>

    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-slackpkg-updatepkglist"></a>17.2.4. Actualitzar la llista de paquets.</h3></div></div></div>
      

      <p>
	Abans d'actualitzar i instal·lar paquets has de deixar que
	slackppg descarregue la llista de paquets de l'espill que
	estàs utilitzant. És una bona idea fer-ho amb regularitat
	per a mantindre la llista de paquets al dia. L'últim llistat
	de paquets es pot recuperar amb:

        
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>slackpkg update</code></strong>
      </pre>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-slackpkg-upgrade"></a>17.2.5. Actualitzant paquets</h3></div></div></div>
      

      <p>
        El paràmetre <em class="parameter"><code>upgrade</code></em>
	s'utilitza per a actualitzar paquets instal·lats. Cal
	afegir un paràmetre extra per a, de fet, dir-li a 
	<span class="command"><strong>slackpkg</strong></span> què vols actualitzar, açò varia
	entre una Slackware Linux stable i una slackware-current.
	Les actualitzacions per alliberaments stable estàn al 
	directori <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">patches</code></html:span> dels espills FTP.
	Es pot posar al dia una instal·lació slackware-stable (
	per exemple Slackware Linux 12.0) mitjançant:

        
      </p>


      <pre class="screen">
# <strong class="userinput"><code>slackpkg upgrade patches</code></strong>
      </pre>

      <p>
	
	En aquest cas, <span class="command"><strong>slackpkg</strong></span> utilitzarà els paquets del
	directori <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">patches</code></html:span>, mentres que els paquets
	actualitzats a slackware-current estàn posats als sub-directoris normals
	de paquets <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">slackware</code></html:span>, així que podem passar-ho com 
	a paràmetre a <span class="command"><strong>slackpkg upgrade</strong></span>:
	
        
      </p>

      <pre class="screen">
# <strong class="userinput"><code>slackpkg upgrade slackware</code></strong>
      </pre>

      <p>
	A més, pots posar al dia paquets individuals especificant el nom
	del paquet a actualitzar, per exemple:
	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>slackpkg upgrade pine</code></strong>
      </pre>

    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-slackpkg-install"></a>17.2.6. Instal·lant paquets</h3></div></div></div>
      

      <p>
	El paràmetre <em class="parameter"><code>install</code></em> s'utilitza
	per a instal·lar paquets:

        
      </p>

      <pre class="screen">
# <strong class="userinput"><code>slackpkg install rexima</code></strong>
      </pre>

      <p>
	S'ha de tindre en compte que ni slackpkg, ni les eines d'empaquetat 
	de Slackware Linux comproven dependències. Si algún programa no 
	funciona a causa de la manca de llibreries, s'hauràn d'instal·lar
	mitjançant slackpkg.
        
      </p>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-pkgmgmt-rsync"></a>17.3. Obtenint actualitzacions mitjançant rsync 
    </h2></div></div></div>
    

    <p>
      Un altre popular mètode de mantindre Slackware Linux al dia és 
      mantenint un espill local. La manera ideal de fer açò és mitjançant
      rsync. rsync és un programa capaç de sincronitzar dos arbres de 
      fitxers. L'avantatge és que rsync només transfereix les diferències
      en fitxers, fent que siga molt ràpid. Després de sincronitzar amb
      un espill, tú pots sincronitzar Slackware Linux amb 
      <span class="command"><strong>upgradepkg</strong></span>, o fer un CD d'instal·lació nou. El
      seguent exemple sincronitza un arbre local amb un arbre d'un 
      espill, que està al dia.

      
    </p>

    <pre class="screen">
# <strong class="userinput"><code>rsync -av --delete \
--exclude=slackware/kde \
--exclude=slackware/kdei \
--exclude=slackware/gnome \
--exclude=bootdisks \
--exclude=extra \
--exclude=testing \
--exclude=pasture \
--exclude=rootdisks \
--exclude=source \
--exclude=zipslack \
rsync://fill-in-mirror/pub/slackware/slackware-current/ \
/usr/share/mirrors/slackware-current</code></strong>
    </pre>

    <p>
      El paràmetre <em class="parameter"><code>-a</code></em> ???implica???  agrupa???
      algunes altres opciones que intenten fer una còpia que siga tan
      exacta com siga possible (en termes de manteniment d'enllaços 
      simbòlics, permisos i propietaris). El paràmetre 
      <em class="parameter"><code>--delete</code></em>
      esborra els fitxers que ja no estàn disponibles a l'espill. És una
      bona idea utilitzar este paràmetre, perque sino el teu arbre es 
      pot inflar ràpidament amb versions antigues de paquets. Amb
      el paràmetre <em class="parameter"><code>--exclude</code></em> es 
      pot especificar quins fitxers o directoris s'haurien d'ignorar.
      
      
    </p>

    <p>
      Després de sincronitzar l'arbre, pots utilitzar 
      <span class="command"><strong>upgradepkg</strong></span> per a actualitzar la teua instal·lació 
      de Slackware Linux. Per exemple:
      
    </p>

    <pre class="screen">
# <strong class="userinput"><code>upgradepkg /usr/share/mirrors/slackware-current/slackware/*/*.tgz</code></strong>
    </pre>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-pkgmgmt-tagfiles"></a>17.4. Tagfiles (fitxers d'etiquetes)</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-tagfiles-intro"></a>17.4.1. Introducció</h3></div></div></div>
      

      <p>
	Els tagfiles (fitxers d'etiquetes) són una característica relativament 
	desconeguda de Slackware linux. Un tagfile és un fitxer que pot ser
	utilitzat per a indicar-li a <span class="command"><strong>upgradepkg</strong></span> quins 
	paquets d'una col·lecció s'haurien d'instal·lar. Per exmple, 
	l'instal·lador de Slackware Linux genera un tagfile durant els 
	mètodes <span class="emphasis"><em>Expert</em></span> i <span class="emphasis"><em>Menu</em></span>
	per a emmagatzemar quins paquets s'haurien d'instal·lar durant el 
	procés d'instal·lació.
        
      </p>

      <p>
	L'aspecte interessant dels tagfiles és que pots crear-ne tú mateix 
	fàcilment. Escrivint els teus propis tagfiles pots automatitzar
	la instal·lació de paquets, el que és ideal per a grans desplegaments
	de clients o servidors (o xicotetes instal·lacions si et resulta
	més còmode que anar instal·lant paquest manualment). La forma més
	senzilla de crear els teus propis tagfiles és basar-te en els 
	que són part de la distribució oficial. A les seccions seguents anem
	a veurer com es fa açò.

        
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-tagfiles-creating"></a>17.4.2. Creant tagfiles </h3></div></div></div>
      

      <p>
	Els tagfiles són simples fitxers de text cru. Cada línia consisteix
	en un nom de paquet i una bandera, aquests dos elements romanen
	separats per : i un espai. La bandera especifica que s'hauria de fer
	amb el paquet. Els camps estàn descrits a  <a class="xref" href="#chap-pkgmgmt-tagfiles-creating-fields" title="Table 17.1. Capms de tagfile">Table 17.1, “Capms de tagfile”</a>. Vejam algunes 
	línies del tagfile al conjunt de disc <span class="quote">“<span class="quote">a</span>”</span>:

        
      </p>

      <pre class="screen">
aaa_base: ADD
aaa_elflibs: ADD
acpid: REC
apmd: REC
bash: ADD
bin: ADD
      </pre>

      <p>
	S'ha de dir que a més pots afegir comentaris als tagfiles amb el
	típic caràcter de comentari (#). Com pots veurer en la captura 
	de pantalla de dalt hi ha banderes diferents. La taula que hi ha a
	continuació descriu les quatre banderes.
        
      </p>

      <div class="table">
<a name="chap-pkgmgmt-tagfiles-creating-fields"></a><p class="title"><b>Table 17.1. Capms de tagfile</b></p>
<div class="table-contents">
        
        <table summary="Capms de tagfile" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th align="left">Bandera</th>
<th align="left">Significat</th>
</tr></thead>
<tbody>
<tr>
<td align="left">ADD</td>
<td align="left">Un paquet marcat amb aquesta bandera s'instal·larà
	      automàticament.
</td>
</tr>
<tr>
<td align="left">SKP</td>
<td align="left">Un paquet marcat amb aquesta bandera es saltarà
	      automàticament.
</td>
</tr>
<tr>
<td align="left">REC</td>
<td align="left">Preguntar a l'usuari què vol fer, es recomanarà 
	      instal·lar-lo.
</td>
</tr>
<tr>
<td align="left">OPT</td>
<td align="left">Preguntar a l'usuari què vol fer, el paquet serà descrit
	      com opcional.
</td>
</tr>
</tbody>
</table>
      </div>
</div>
<br class="table-break">

      <p>
	Com pots llegir a la taula, <span class="command"><strong>installpkg</strong></span> només 
	actuarà automàticament quan s'utilitze 
	<span class="emphasis"><em>ADD</em></span> o <span class="emphasis"><em>SKP</em></span>.
        
      </p>

      <p>
	Seria una miqueta tediós escriure un tagfile per a cada conjunt
	de disc de Slackware. La distribució Slackware Linux oficial conté 
	un tagfile al directori corresponent de cada conjunt de disc que 
	pots utilitzar per començar. El script curt que es llista baix es 
	pot utilitzar per a copiar els tagfiles al directori actual, preservant
	la estructura del conjunt de discs.

        
      </p>

      <pre class="screen">
#!/bin/sh

if [ ! $# -eq 1 ] ; then
  echo "Syntax: $0 [directory]"
  exit
fi

for tagfile in $1/*/tagfile; do 
  setdir=`echo ${tagfile} | egrep -o '\w+/tagfile$' | xargs dirname`
  mkdir ${setdir}
  cp ${tagfile} ${setdir}/tagfile.org
  cp ${tagfile} ${setdir}
done
      </pre>

      <p>
	Després d'alçar el guió en un fitxer, el pots executra i 
	especificar un directori <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">slackware/</code></html:span>
	que proporcione conjunts de discs. Per exemple:
        
      </p>

      <pre class="screen">
$ <span class="command"><strong>sh copy-tagfiles.sh /mnt/flux/slackware-current/slackware</strong></span>
      </pre>

      <p>
	Després de fer açò el dicrectori actual contindrà una estructura de
	directoris com esta, en la que pots editar cada tagfile individualment:
        
      </p>

      <pre class="screen">
a/tagfile
a/tagfile.org
ap/tagfile
ap/tagfile.org
d/tagfile
d/tagfile.org
e/tagfile
e/tagfile.org
[...]
      </pre>

      <p>
	Els fitxers que acaben amb <span class="emphasis"><em>.org</em></span> són còpies de
	seguretat que pots utilitzar com a referència mentres edites tagiles.
	A més d'això també s'utilitzen al guió què es descriu a la secció 
	seguent:
        
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-tagfiles-autogen"></a>17.4.3. Generant tagfiles automàticament 
      </h3></div></div></div>
      

      <p>
	Amb un senzill script, també és possible construir tagfiles
	basats en paquets que están instal·lats en el sistema actual.
	Li estic molt agraït a Peter Kaagman per aparéixer amb aquesta
	enginyosa idea!
        
      </p>

      <p>
	Primer munta un directori tagfile del medi d'instal·lació 
	de Slackware Linux, com s'ha descrit a la secció anterior. Quan
	ho hajes fet, pots crear el següent script:

        
      </p>

      <pre class="screen">
#!/bin/sh

if [ ! $# -eq 1 ] ; then
  echo "Syntax: $0 [directory]"
  exit
fi

for tforg in $1/*/tagfile.org ; do
  tf=${tforg%.org}
  rm -f ${tf}
  for package in $(grep -v '^#' ${tforg} | cut -d ':' -f 1) ; do
    if ls /var/log/packages/${package}-[0-9]* &amp;&gt; /dev/null ; then 
      echo "${package}: ADD" &gt;&gt; ${tf}
    else
      echo "${package}: SKP" &gt;&gt; ${tf}
    fi
  done
done
      </pre>

      <p>
	Suposem que l'has alçat com <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">build-tagfiles.sh</code></html:span>,
	el pots utilitzar especificant el directori que conté els tagfiles
	com el primer argument:

        
      </p>

      <pre class="screen">
$ <strong class="userinput"><code>sh build-tagfiles.sh .</code></strong>
      </pre>

      <p>
	El script marcarà els paquets que estan instal·lats com 
	<span class="emphasis"><em>ADD</em></span>, i els paquets que no estàn instal·lats
	com <span class="emphasis"><em>SKP</em></span>.
        
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-pkgmgmt-tagfiles-using"></a>17.4.4. Utilitzant tagfiles </h3></div></div></div>
      

      <p>
	A sistemes instal·lats pots deixar que <span class="command"><strong>installpkg</strong></span>
	utilitze un tagfile amb el paràmetre 
	<em class="parameter"><code>-tagfile</code></em>. Per exemple:

        
      </p>

      <pre class="screen">
# <strong class="userinput"><code>installpkg -infobox -root /mnt-small -tagfile a/tagfile /mnt/flux/slackware-current/slackware/a/*.tgz</code></strong>
      </pre>

      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
	<p>
	  Has d'utilitzar la opció <em class="parameter"><code>-infobox</code></em>, sino els tagfiles no 
	  s'utilitzaràn.

	  
	</p>
      </td></tr>
</table></div>

      <p>
	Presupost, els tagfiles serien inútils si no es pogureren utilitzar
	durant la instal·lació de Slackware Linux. Açò és completament
	possible: després de seleccionar quins conjunts de discs vols 
	instal·lar, pots triar de quina manera vols seleccionar els 
	paquets (el nom del diàleg és <span class="emphasis"><em>SELECT PROMPTING
        MODE</em></span>). Selecciona <span class="emphasis"><em>tagpath</em></span> en este menú.
	Aleshores se't demanarà	que introduisques el camí a la estructura
	de directoris amb els tagfiles. La forma típica de proporcionar
	els tagfiles a la instal·lació de Slackware Linux és posar-los en un
	disquet o un altre medi i muntar-lo abans o durant la instal·lació.
	P. ex. pots canviar a la segona consola pitjant les tecles &lt;ALT&gt; 
	i &lt;F2&gt;, crear el punt de muntatge i muntar el disc amb els 
	tagfiles:

        
      </p>

      <pre class="screen">
# <strong class="userinput"><code>mkdir /mnt-tagfiles</code></strong>
# <strong class="userinput"><code>mount /dev/fd0 /mnt/mnt-tagfiles</code></strong>
      </pre>

      <p>
	Després de muntar el disc pots tornar a la consola virtual en 
	la que vas inicar <span class="command"><strong>setup</strong></span> pressionant &lt;ALT&gt;
	and &lt;F1&gt;.
        
      </p>
    </div>
  </div>
</div>
    <div lang="en" class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="kernel"></a>Chapter 18. Contruïnt un núcli</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-kernel-intro">18.1. Introducció</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-build">18.2. Configuració</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-compile">18.3. La compilació</a></span></dt>
<dt><span class="sect1"><a href="#chap-kernel-install">18.4. Instal·lació</a></span></dt>
</dl>
</div>
  

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-kernel-intro"></a>18.1. Introducció</h2></div></div></div>
    

    <p>
		El núcli Linux s'explica breument a <a class="xref" href="#chap-intro-linux" title="2.1. Què és Linux?">Section 2.1, “Què és Linux?”</a>. Un dels avantatges de Linux és
		que el codi font complet està disponible (com passa amb la majoria 
		del	programari del sistema Slackware Linux). Açò significa que es
		pot recompilar el nucli. Hi ha situacions en que resulta útil 
		fer-ho, per exemple:
      
    </p> 

    <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	<p>
		<span class="bold"><strong>Aprimar el nucli</strong></span>:
		Es poden deshabilitar funcionalitats concretes del núcli per a
		reduir el seu tamany. Açò és especialment útil en entorns amb 
		poca memòria RAM.
	  
	</p>
      </li>
<li class="listitem">
	<p>
		<span class="bold"><strong>Optimizing the kernel</strong></span>: és 
		possible optimitzar el núcli. Per exemple, compilant-lo per a un
		tipus de processador específic.
	  
	</p>
      </li>
<li class="listitem">
	<p>
		<span class="bold"><strong>Suport de maquinari</strong></span>: Hi ha 
		maquinari que per defecte no està suportat pel núcli proporcionat
		per Slackware Linux. Un exemple típic és el suport per als 
		sistemes SMP.
	  
	</p>
      </li>
<li class="listitem">
	<p>
		<span class="bold"><strong>Emprant tapas personalitzats</strong></span>:
		Hi han molts tapats no oficials per al núcli Linux. Per regla 
		general evitar aquests tapats és una bona idea, però ???cert???
		programari de tercers, com <a class="ulink" href="http://www.win4lin.com" target="_top">
		Win4Lin</a>, requereix que s'instale un tapat adicional del
		nucli.
	  
	</p>
      </li>
<li class="listitem">
	<p>
		Crear les capçaleres adequades i muntar una infraestructura
		disponible per a construir mòduls de tercers.
	  
	</p>
      </li>
</ul></div>

    <p>
		Aquets capítol posa el focus en la sèrie de núclis emprada en 
		Slackware Linux 12.0, la Linux 2.6. Compilar un núcli no és 
		realment difícil, simplement tingues a ma una còpia de seguretat 
		del núcli que pugues utilitzar si alguna cosa anara malament. 
		La compilació del núcli Linux consta d'aquests	passos:
      
    </p>

    <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
	<p>
	  Configurar el núcli.
	</p>
      </li>
<li class="listitem">
	<p>
	  Contruir el núcli. 
	</p>
      </li>
<li class="listitem">
	<p>
	  Construir els mòduls. 
	</p>
      </li>
<li class="listitem">
	<p>
	  Instal·lar el núcli i els mòduls. 
	</p>
      </li>
<li class="listitem">
	<p>
	  Actualitza la configuració del LILO. 
	</p>
      </li>
</ul></div>
    
    <p>
		Al llarg d'aquest capítol, entendrem que els codis font del 
		núcli es troben a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/src/linux</code></html:span>. Si has
		instal·lat el paquet kernel-soruces del conjunt de discs 
		<span class="quote">“<span class="quote">k</span>”</span>, les fonts del núcli estaràn disponibles al 
		directori <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/src/linux-kernelversion</code></html:span>, i
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/src/linux</code></html:span> serà un enllaç simbòlic al 
		directori real de les fonts. D'aquesta manera, si empres els 
		paquet estàndard de núclis Linux d'Slackware ets a punt per a 
		continuar.
      
    </p>

    <p>
		A diferència de les versions més antigues del núcli,
		ja no cal l'enllaç simbòlic <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/src/linux</code></html:span>. 
		Si has extet les fonts del nou núcli a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/src</code></html:span>,
		podràs contruir el núcli a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/src/linux-&lt;version&gt;
		</code></html:span>, i utilitzar eixe directori en els exemples d'aquest 
		capítol.
      
    </p>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-kernel-build"></a>18.2. Configuració</h2></div></div></div>
    

    <p>
		Adés em dit, que el primer pas és configurar les 
		fonts del núcli. Per a facilitar aquesta tasca és convenient
		copiar la configuració dels fonts del núcli Linux que que venen 
		per defècte a la distribució a les fonts del núcli. Aquests 
		fitxers estàn emmagatzemats al medi de la distribució com <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">
		kernels/&lt;kernelname&gt;/config</code></html:span>. Suposem que volem 
		utilitzar la configuració del núcli <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hugesmp.s</code></html:span>
		com a punt de partida (què és el núcli per defecte), i que tenim
		un CD-ROM de Slackware Linux muntat a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/mnt/cdrom</code></html:span>,
		llavors podríem copiar la configuració del núcli Linux mitjançant
		la ordre:
		
      
    </p>
    
    <pre class="screen">
# <strong class="userinput"><code>cp /mnt/cdrom/kernels/hugesmp.s/config /usr/src/linux/.config</code></strong>
    </pre>

    <p>
		La configuració d'un nucli en execució també es pot obtindre
		com <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/proc/config.gz</code></html:span> sempre i quan el núcli 
		estiga compilat amb les opcions <span class="emphasis"><em>CONFIG_IKCONFIG</em></span> 
		i <span class="emphasis"><em>CONFIG_IKCONFIG_PROC</em></span>. Els núclis per 
		defecte de Slackware Linux tenen aquestes opcions activades, 
		pel que si volguerem utilitzar la configuració del kernel en 
		execució, podríem executar:
      
    </p>

    <pre class="screen">
# <strong class="userinput"><code>zcat /proc/config.gz &gt; /usr/src/linux/.config</code></strong>
    </pre>

    <p>
		Si estàs utilitzant un fitxer de configuració d'una versió 
		diferent a la del núcli que estàs compilant, és molt probable
		que ambdúes versions no tinguen el mateix conjunt d'opcions. 
		S'afigen noves opcions sovint (per exemple, perque s'han afegit
		drivers més nous), i de vegades s'eliminen components del núcli.
		Es poden configurar noves opcions (i eliminar les que no
		utilitzes) amb la ordre <span class="command"><strong>make oldconfig</strong></span>:
		
		
    </p>

    <p>
# <strong class="userinput"><code>cd /usr/src/linux ; make oldconfig</code></strong>
    </p>

    <p>
		Açò et preguntarà quines opcions vols compilar amb suport, 
		(<span class="emphasis"><em>Y</em></span>), quines amb suport com a mòdul 
		(<span class="emphasis"><em>M</em></span>), i de quines no vols suport 
		(<span class="emphasis"><em>N</em></span>). Per exemple:
     
      
    </p>

    <pre class="screen">
IBM ThinkPad Laptop Extras (ACPI_IBM) [N/m/y/?] (NEW)
    </pre>

    <p>
		Com pots veurer, es mostren les possibles opcions, amb la 
		opció per defècte en majúscules. Si senzillament prems la tecla 
		&lt;Enter&gt;, la opció en majúscules serà utilitzada i si vols
		més informació d'una opció, pots introduïr un interrogant
		(<span class="emphasis"><em>?</em></span>):
				
      
    </p>

    <pre class="screen">
    IBM ThinkPad Laptop Extras (ACPI_IBM) [N/m/y/?] (NEW) <strong class="userinput"><code>?</code></strong>

This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds
support for Fn-Fx key combinations, Bluetooth control, video
output switching, ThinkLight control, UltraBay eject and more.
For more information about this driver see &lt;file:Documentation/ibm-acpi.txt&gt;
and &lt;http://ibm-acpi.sf.net/&gt; .

If you have an IBM ThinkPad laptop, say Y or M here.

    IBM ThinkPad Laptop Extras (ACPI_IBM) [N/m/y/?] (NEW)
    </pre>

    <p>
		La eixida d'aquest comandament pot ser una miqueta extensa, 
		perque es mostren les opcions que van ser utilitzades en el 
		fitxer de configuració i les que estàn disponibles en el núcli 
		en execució, però la configuració es farceix automàticament 
		basant-se en el fitxer de configuració.
		
      
    </p>
    
    <p>
		Arribats a este punt, podem començar a configurar el núcli amb 
		detall. Hi ha tres ??caretes?? per a la configuració del núcli.
		La primera és <em class="parameter"><code>config</code></em>, que
		senzillament ens pregunta què volem fer amb cada opció del núcli.
		Aquesta opció requereix molt de temps, pel que no és considera
		una bona manera de configurar el núcli. Una aproximació molt més
		amigables és la careta <em class="parameter"><code>menuconfig
		</code></em>, que utilitza un sistema de menús per a fer la tasca.
		També hi ha una interfície de X, anomenada <em class="parameter"><code>xconfig</code></em>. Per a iniciar una careta
		canviant al directori de fonts del núcli i executant <span class="command"><strong>make
		&lt;front-end&gt;</strong></span>. Per exemple, per a configurar el
		núcli amb la interfície de menús, pots utilitzar les següents
		ordres:
      
    </p>
    
    <pre class="screen">
# <strong class="userinput"><code>cd /usr/src/linux</code></strong>
# <strong class="userinput"><code>make menuconfig</code></strong>
    </pre>
    
    <p>
		Pressupost que, si així ho prefereixes, també pots editar el
		fitxer <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">.config</code></html:span> directament amb el teu 
		editor favorit.
      
    </p>

    <p>
		Com hem vist breument abans, en la configuració del núcli hi ha
		bàsicament tres opcions per a cada elecció: <span class="quote">“<span class="quote">n</span>”</span>
		deshabilita la funcionalitat, <span class="quote">“<span class="quote">y</span>”</span> la habilita, i
		<span class="quote">“<span class="quote">m</span>”</span> la compila com a mòdul. La configuració del 
		núcli Slackware Linux que ve per defecte és una configuració 
		molt bona, inclou suport per a les controladoes de disk i 
		sistemes de fitxers més comuns, mentres que la resta ve compilat
		com a mòdul. Siguen quines siguen les deicisions que prengues, 
		t'has d'assegurar de que inclous tant el driver per a la 
		controladora de discs com suport per al tipus de sistema de
		fitxers en què tens instal·lat el teu sistema de fitxers arrel. 
		De no és així, el núcli no serà capaç de muntar el sistema de 
		fitxers arrel, i el núcli "entrarà en pànic" al no poder 
		entregar-li el control de l'inicialització al programa 
		<span class="command"><strong>init</strong></span>.
      
    </p>

    <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
      <p>
		  Sempre és una bona idea mantindre el teu vell núcli a prop
		  en mòduls per si comets un error de configuració. Si el núcli a 
		  compilar té el mateix nombre de versió que el núcli en
		  funcionament, hauries de considerar seriosament si modificar 
		  la opció <span class="emphasis"><em>CONFIG_LOCALVERSION</em></span>. La cadena
		  especificada en esta opció afegida al final del nom de la
		  versió. Per exemple, si el núcli té la versió 2.6.21.6, i a
		  <span class="emphasis"><em>CONFIG_LOCALVERSION</em></span> està posat 
		  <span class="emphasis"><em>"-smp-ddk"</em></span>, la versió del núcli serà
		  <span class="emphasis"><em>2.6.21.6-smp-ddk</em></span>.
	
      </p>

      <p>
		  Si no modifiques la versió d'aquesta manera, la instal·lació
		  dels mòduls del nou núcli sobreescriurà els mòduls del núcli
		  en execució. Açò és enormement incòmode si necessites tornar
		  al vell núcli.
	
      </p>
    </td></tr>
</table></div>
  </div>
  
  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-kernel-compile"></a>18.3. La compilació</h2></div></div></div>
    

    <p>
		La compilació del núcli solia consistir de múltiples passos,
		però el núclis Linux 2.6 es poden compilar executant 
		<span class="command"><strong>make</strong></span> en el directori dels fonts del núcli.
		Açò calcularà dependències, construirà el núcli i construirà i 
		enllaçarà els mòduls del núcli.
      
    </p>

    <pre class="screen">
# <strong class="userinput"><code>cd /usr/src/linux</code></strong>
# <strong class="userinput"><code>Construcció (make)</code></strong>
    </pre>
    
    <p>
		Una vegada compilat, l'arbre conté els mòduls i un imatge 
		comprimida del núcli anomenada <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">bzImage</code></html:span> a 
		<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/src/linux/arch/i386/boot</code></html:span>. Ara es pot
		continuar amb la instal·lació del núcli i dels mòduls.
      
    </p>
  </div>
  
  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-kernel-install"></a>18.4. Instal·lació</h2></div></div></div>
    
    
    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-kernel-install-kernel"></a>18.4.1. Instal·lant el núcli</h3></div></div></div>
      
      
      <p>
		  El següent pas és instal·lar el núcli amb els seus mòduls.
		  S'acomença instal·lant els mòduls perquè açò es pot fer amb
		  una ordre dins del arbre de fonts:
	
      </p>
      
      <pre class="screen">
# <strong class="userinput"><code>make modules_install</code></strong>
      </pre>
      
      <p>
		  Açò instal·larà els moduls a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">
		  /lib/modules/&lt;kernelversion&gt;</code></html:span>. Si s'està 
		  reemplaçant un núcli amb exactament el mateixa nombre de versió,
		  és una bona idea eliminar els mòduls antincs abans:
		  
		  
	
      </p>
	
      <pre class="screen">
# <strong class="userinput"><code>rm -rf /lib/modules/2.6.21.5-smp</code></strong>
      </pre>
      
      <p>
		  Es pot <span class="quote">“<span class="quote">instal·lar</span>”</span> el núcli copiant-lo al directory
		  <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/boot</code></html:span> i li pots donar el nom que vullgues,
		  només què és una bona idea utilitzar alguna convenció per als
		  noms, com <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">vmlinuz-version</code></html:span>. Per exemple, si
		  l'anomenes <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">vmlinuz-2.6.21.5-smp-ddk</code></html:span>, el pots
		  copiar desde l'arbre de fonts del núcli amb la ordre:
		  
		  
	
      </p>
      
      <pre class="screen">
# <strong class="userinput"><code>cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.21.5-smp-ddk</code></strong>
      </pre>
      
      <p>
		  En este punt, quasi em acabat. L'últim pas és afegir el nou
		  núcli a la configuració del carregador del llançament de Linux 
		  (LILO).
	
      </p>
    </div>
    
    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-kernel-install-lilo"></a>18.4.2. Configurant LILO</h3></div></div></div>
      
      
      <p>
		<acronym class="acronym">LILO</acronym> (Linux Loader) és el llançador de la 
		càrrega de Linux que utilitza Slackware Linux per defecte. La 
		configuració de LILO funciona en dos passos; primer es modifica
		la configuració en <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/lilo.conf</code></html:span> i després
		s'executa <span class="command"><strong>lilo</strong></span>, qui escriurà la nova configuració
		en el llançador de càrrega. La configuració de LILO ja té una 
		entrada per al núcli actualment en funcionament. És molt bona idea
		deixar esta entrada per si de cas el nou núcli no funciona, si 
		et mous al final del fitxer <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/lilo.conf</code></html:span>
		la veuràs, i s'assemblarà a açò:
        
      </p>
      
      <pre class="screen">
# Linux bootable partition config begins
image = /boot/vmlinuz
  root = /dev/hda5
  label = Slack
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking
# Linux bootable partition config ends
      </pre>
      
      <p>
		  La forma més senzilla de afegir el nou núcli és duplicar la 
		  entrada existent i editar la primera entrada, modificant les
		  opcions <em class="parameter"><code>image</code></em>, i <em class="parameter"><code>label</code></em>.
		  Després dels canvis l'exemple d'abans es pareixerà a açò:
		  
        The easiest way to add the new kernel is to duplicate the
        existing entry, and then editing the first entry, changing the
        <em class="parameter"><code>image</code></em>, and <em class="parameter"><code>label</code></em>
        options. After changing the example above it would look like
        this:
      </p>
      
      <pre class="screen">
# Linux bootable partition config begins
image = /boot/vmlinuz-2.6.21.5-smp-ddk
  root = /dev/hda5
  label = Slack
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking

image = /boot/vmlinuz
  root = /dev/hda5
  label = SlackOld
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking
# Linux bootable partition config ends
      </pre>
      
      <p>
		Com es pot veurer, la primera entrada de <em class="parameter"><code>image</code></em>
		apunta al nou núcli, i la etiqueta (label) de la segona s'ha 
		canviat a <span class="quote">“<span class="quote">SlackOld</span>”</span>. LILO llançarà automàticament
		la primera imatge. Ara es pot instal·lar aquesta configuració de
		LILO amb l'ordre <span class="command"><strong>lilo</strong></span>:
	
      </p>

      <pre class="screen">
# <strong class="userinput"><code>lilo</code></strong>
Added Slack *
Added SlackOld
      </pre>

      <p>
		  La pròxima vegada que incies l'ordinador, les dues entrades
		  estaràn disponibles, i la entrada <span class="quote">“<span class="quote">Slack</span>”</span> serà
		  llançada per defecte.
	
      </p>
      
      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
	<p>
		Si vols que LILO mostre un menú amb les entrades configurades
		via <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">lilo.conf</code></html:span> cada vegada que encengues 
		l'ordinador, assabenta't de que afegeixes una línea que diga:
	  
	</p>

	<pre class="screen">
prompt
	</pre>

	<p>
		al <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">lilo.conf</code></html:span>. D'altra manera LILO 
		llançarà la entrada per defecte què es defineix amb <span class="emphasis"><em>
		default=&lt;name&gt;</em></span>, o la primera entrada si no 
		se n'especifica cap. Sempre es pot accedir al menú mantenint
		pitjada la tecla &lt;Shift&gt; quan LILO està en marxa.
		
	</p>
      </td></tr>
</table></div>
    </div>
  </div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-init"></a>Chapter 19. System initialization</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#chap-init-lilo">19.1. The bootloader</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-init">19.2. init</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-initscripts">19.3. Initialization scripts</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-udev">19.4. Hotplugging and device node management</a></span></dt>
<dt><span class="sect1"><a href="#chap-init-firmware">19.5. Device firmware</a></span></dt>
</dl>
</div>
  

  <p>
    This chapter describes the initialization of Slackware
    Linux. Along the way various configuration files that are used to
    manipulate the initialization process are described.
  </p>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-init-lilo"></a>19.1. The bootloader</h2></div></div></div>
    

    <p>
      Arguably the most important piece of an operating system is the
      kernel. The kernel manages hardware resources and software
      processes.  The kernel is started by some tiny glue between the
      system <acronym class="acronym">BIOS</acronym> (Basic Input/Output System) and
      the kernel, called the bootloader. The bootloader handles the
      complications that come with loading a specific (or less
      specific) kernel.
    </p>

    <p>
      Most bootloader actually work in two stages. The first stage
      loader loads the second stage loader, that does the real
      work. The boot loader is divided in two stages on x86 machines,
      because the BIOS only loads one sector (the so-called boot
      sector) that is 512 bytes in size.
    </p>

    <p>
      Slackware Linux uses the <acronym class="acronym">LILO</acronym> (LInux LOader)
      boot loader. This bootloader has been in development since 1992,
      and is specifically written to load the Linux kernel. Lately
      LILO has been replaced by the <acronym class="acronym">GRUB</acronym> (GRand
      Unified Bootloader) in most GNU/Linux distributions. GRUB is
      available as an extra package on the Slackware Linux
      distribution media.
    </p>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-init-lilo-config"></a>19.1.1. LILO configuration</h3></div></div></div>
      

      <p>
	LILO is configured through the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/lilo.conf</code></html:span> configuration
	file. Slackware Linux provides an easy tool to configure
	LILO. This configuration tool can be started with the
	<span class="command"><strong>liloconfig</strong></span> command, and is described in the
	installation chapter (<a class="xref" href="#chap-install-installing" title="5.3. Instal·lant Slackware Linux">Section 5.3, “Instal·lant Slackware Linux”</a>).
      </p>

      <p>
	Manual configuration of LILO is pretty simple. The LILO
	configuration file usually starts off with some global
	settings:
      </p>

      <pre class="screen">
# Start LILO global section
boot = /dev/sda <a name="liloconf-global-1"></a><span><img src="../images/callouts/1.png" alt="1" border="0"></span>
#compact        # faster, but won't work on all systems.
prompt <a name="liloconf-global-2"></a><span><img src="../images/callouts/2.png" alt="2" border="0"></span>
timeout = 50 <a name="liloconf-global-3"></a><span><img src="../images/callouts/3.png" alt="3" border="0"></span>
# Normal VGA console
vga = normal <a name="liloconf-global-4"></a><span><img src="../images/callouts/4.png" alt="4" border="0"></span>
      </pre>

      <div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a href="#liloconf-global-1"><span><img src="../images/callouts/1.png" alt="1" border="0"></span></a> </p></td>
<td valign="top" align="left">
	  <p>
	    The <span class="emphasis"><em>boot</em></span> option specifies where the
	    LILO bootloader should be installed. If you want to use
	    LILO as the main bootloader for starting Linux and/or
	    other operating systems, it is a good idea to install LILO
	    in the <acronym class="acronym">MBR</acronym> (Master Boot Record) of the
	    hard disk that you use to boot the system. LILO is
	    installed to the MBR by omitting the partition number, for
	    instance <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/hda</code></html:span> or
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/sda</code></html:span>.  If you want to install
	    LILO to a specific partition, add a partition number, like
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/sda1</code></html:span>.  Make sure that you have
	    another bootloader in the MBR, or that the partition is
	    made active using <span class="command"><strong>fdisk</strong></span>.  Otherwise you
	    may end up with an unbootable system.
	  </p>

	  <p>
	    Be cautious if you use partitions with a XFS filesystem!
	    Writing LILO to an XFS partition will overwrite a part of
	    the filesystem. If you use an XFS root
	    (<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span>) filesystem, create a non-XFS
	    <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/boot</code></html:span> filesystem to which you install
	    LILO, or install LILO to the MBR.
	  </p>
	</td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#liloconf-global-2"><span><img src="../images/callouts/2.png" alt="2" border="0"></span></a> </p></td>
<td valign="top" align="left">
	  <p>
	    The <span class="emphasis"><em>prompt</em></span> option will set LILO to
	    show a boot menu. From this menu you can select which
	    kernel or operating system should be booted. If you do not
	    have this option enabled, you can still access the
	    bootloader menu by holding the &lt;Shift&gt; key when the
	    bootloader is started.
            </p>
	</td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#liloconf-global-3"><span><img src="../images/callouts/3.png" alt="3" border="0"></span></a> </p></td>
<td valign="top" align="left">
	  <p>
	    The <span class="emphasis"><em>timeout</em></span> value specifies how long
	    LILO should wait before the default kernel or OS is
	    booted.  The time is specified in tenths of a second, so
	    in the example above LILO will wait 5 seconds before it
	    proceeds with the boot.
	  </p>
	</td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#liloconf-global-4"><span><img src="../images/callouts/4.png" alt="4" border="0"></span></a> </p></td>
<td valign="top" align="left">
	  <p>
	    You can specify which video mode the kernel should use
	    with the <span class="emphasis"><em>vga</em></span> option. When this is set
	    to <span class="emphasis"><em>normal</em></span> the kernel will use the
	    normal 80x25 text mode.
	  </p>
	</td>
</tr>
</table></div>

      <p>
	The global options are followed by sections that add Linux
	kernels or other operating systems. Most Linux kernel sections
	look like this:
      </p>

      <pre class="screen">
image = /boot/vmlinuz <a name="co-liloconf-kernel-1"></a><span><img src="../images/callouts/1.png" alt="1" border="0"></span>
  root = /dev/sda5 <a name="co-liloconf-kernel-2"></a><span><img src="../images/callouts/2.png" alt="2" border="0"></span> 
  label = Slack <a name="co-liloconf-kernel-3"></a><span><img src="../images/callouts/3.png" alt="3" border="0"></span>
  read-only <a name="co-liloconf-kernel-4"></a><span><img src="../images/callouts/4.png" alt="4" border="0"></span>
      </pre>

      <div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-liloconf-kernel-1"><span><img src="../images/callouts/1.png" alt="1" border="0"></span></a> </p></td>
<td valign="top" align="left">
	  <p>
	    The <span class="emphasis"><em>image</em></span> option specifies the kernel
	    image that should be loaded for this LILO item.
	  </p>
	</td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-liloconf-kernel-2"><span><img src="../images/callouts/2.png" alt="2" border="0"></span></a> </p></td>
<td valign="top" align="left">
	  <p>
	    The <span class="emphasis"><em>root</em></span> parameter is passed to the
	    kernel, and will be used by the kernel as the root
	    (<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/</code></html:span>) filesystem.
	  </p>
	</td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-liloconf-kernel-3"><span><img src="../images/callouts/3.png" alt="3" border="0"></span></a> </p></td>
<td valign="top" align="left">
	  <p>
	    The <span class="emphasis"><em>label</em></span> text is used as the label
	    for this entry in the LILO boot menu.
	  </p>
	</td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-liloconf-kernel-4"><span><img src="../images/callouts/4.png" alt="4" border="0"></span></a> </p></td>
<td valign="top" align="left">
	  <p>
	    <span class="emphasis"><em>read-only</em></span> specifies that the root
	    filesystem should be mounted read-only. The filesystem has
	    to be mounted in read-only state to conduct a filesystem
	    check.
	  </p>
	</td>
</tr>
</table></div>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-init-lilo-installation"></a>19.1.2. LILO installation</h3></div></div></div>
      

      <p>
	LILO does not read the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/lilo.conf</code></html:span>
	file during the second stage. So, you will have to write
	changes to the second stage loader when you have changed the
	LILO configuration. This is also necessary if you install a
	new kernel with the same filename, since the position of the
	kernel on the disk may have changed. Reinstalling LILO can
	simply be done with the <span class="command"><strong>lilo</strong></span> command:
      </p>

      <pre class="screen">
# <span class="command"><strong>lilo</strong></span>
Added Slack26 *
Added Slack
      </pre>
    </div>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-init-init"></a>19.2. init</h2></div></div></div>
    

    <p>
      After the kernel is loaded and started, the kernel will start
      the <span class="command"><strong>init</strong></span> command. <span class="command"><strong>init</strong></span> is
      the parent of all processes, and takes care of starting the
      system initialization scripts, and spawning login consoles
      through <span class="command"><strong>agetty</strong></span>. The behavior of
      <span class="command"><strong>init</strong></span> is configured in
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/inittab</code></html:span>.
    </p>

    <p>
      The <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/inittab</code></html:span> file is documented fairly
      well. It specifies what scripts the system should run for
      different runlevels. A runlevel is a state the system is running
      in. For instance, runlevel 1 is single user mode, and runlevel 3
      is multi-user mode. We will have a short look at a line from
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/inittab</code></html:span> to see how it works:
    </p>

    <pre class="screen">
rc:2345:wait:/etc/rc.d/rc.M
    </pre>

    <p>
      This line specifies that <span class="command"><strong>/etc/rc.d/rc.M</strong></span>
      should be started when the system switches to runlevel 2, 3, 4
      or 5.  The only line you probably ever have to touch is the
      default runlevel:
    </p>

    <pre class="screen">
id:3:initdefault:
    </pre>

    <p>
      In this example the default runlevel is set to
      <span class="emphasis"><em>3</em></span> (multiuser mode). You can set this to
      another runlevel by replacing 3 with the new default
      runlevel. Runlevel 4 can particularly be interesting on desktop
      machines, since Slackware Linux will try to start the GDM, KDM
      or XDM display manager (in this particular order).  These
      display managers provide a graphical login, and are respectively
      part of GNOME, KDE and X11.
    </p>

    <p>
      Another interesting section are the lines that specify what
      command should handle a console. For instance:
    </p>

    <pre class="screen">
c1:1235:respawn:/sbin/agetty 38400 tty1 linux
    </pre>

    <p>
      This line specifies that <span class="command"><strong>agetty</strong></span> should be
      started on <span class="emphasis"><em>tty1</em></span> (the first virtual
      terminal) in runlevels 1, 2, 3 and 5.  The
      <span class="command"><strong>agetty</strong></span> command opens the tty port, and
      prompts for a login name. <span class="command"><strong>agetty</strong></span> will then
      spawn <span class="command"><strong>login</strong></span> to handle the login. As you can
      see from the entries, Slackware Linux only starts one console in
      runlevel 6, namely <span class="emphasis"><em>tty6</em></span>. One might ask what
      happened to <span class="emphasis"><em>tty0</em></span>, <span class="emphasis"><em>tty0</em></span>
      certainly exists, and represents the active console.
    </p>

    <p>
      Since <span class="emphasis"><em>/etc/inittab</em></span> is the right place to
      spawn <span class="command"><strong>agetty</strong></span> instances to listen for logins,
      you can also let one or more agetties listen to a serial
      port. This is especially handy when you have one or more
      terminals connected to a machine. You can add something like the
      following line to start an <span class="command"><strong>agetty</strong></span> instance
      that listens on COM1:
    </p>

    <pre class="screen">
s1:12345:respawn:/sbin/agetty -L ttyS0 9600 vt100
    </pre>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-init-initscripts"></a>19.3. Initialization scripts</h2></div></div></div>
    

    <p>
      As explained in the <span class="command"><strong>init</strong></span> (<a class="xref" href="#chap-init-init" title="19.2. init">Section 19.2, “init”</a>) section,
      <span class="command"><strong>init</strong></span> starts some scripts that handle
      different runlevels. These scripts perform jobs and change
      settings that are necessary for a particular runlevel, but they
      may also start other scripts. Let's look at an example from
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.M</code></html:span>, the script that
      <span class="command"><strong>init</strong></span> executes when the system switches to a
      multi-user runlevel:
    </p>

    <pre class="programlisting">
# Start the sendmail daemon:
if [ -x /etc/rc.d/rc.sendmail ]; then
  . /etc/rc.d/rc.sendmail start
fi
    </pre>

    <p>
      These lines say <span class="quote">“<span class="quote">execute <span class="command"><strong>/etc/rc.d/rc.sendmail
      start</strong></span> if <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.sendmail</code></html:span> is
      executable</span>”</span>. This indicates the simplicity of the
      Slackware Linux initialization scripts. Different functionality,
      for instance network services, can be turned on or off, by
      twiddling the executable flag on their initialization script.
      If the initialization script is executable, the service will be
      started, otherwise it will not. Setting file flags is described
      in <a class="xref" href="#chap-filesystem-permissions-permbits" title="8.5.2. Changing file permission bits">Section 8.5.2, “Changing file permission bits”</a>, but
      we will have a look at a quick example how you can enable and
      disable sendmail.
    </p>

    <p>
      To start sendmail when the system initializes, execute:
    </p>

    <pre class="screen">
# <span class="command"><strong>chmod +x /etc/rc.d/rc.sendmail</strong></span>
    </pre>

    <p>
      To disable starting of sendmail when the system initializes,
      execute:
    </p>

    <pre class="screen">
# <span class="command"><strong>chmod -x /etc/rc.d/rc.sendmail</strong></span>
    </pre>

    <p>
      Most service-specific initialization scripts accept three
      parameters to change the state of the service:
      <span class="emphasis"><em>start</em></span>, <span class="emphasis"><em>restart</em></span> and
      <span class="emphasis"><em>stop</em></span>. These parameters are pretty much self
      descriptive. For example, if you would like to restart sendmail,
      you could execute:
    </p>

    <pre class="screen">
# <span class="command"><strong>/etc/rc.d/rc.sendmail restart</strong></span>
    </pre>

    <p>
      If the script is not executable, you have to tell the shell that
      you would like to execute the file with
      <span class="command"><strong>sh</strong></span>. For example:
    </p>

    <pre class="screen">
# <span class="command"><strong>sh /etc/rc.d/rc.sendmail start</strong></span>
    </pre>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-init-udev"></a>19.4. Hotplugging and device node management</h2></div></div></div>
    

    <p>
      Slackware Linux has supported hotplugging since Slackware Linux
      9.1.  When enabled, the kernel passes notifications about device
      events to a userspace command. Since Slackware Linux 11.0,
      the <span class="command"><strong>udev</strong></span> set of utilities handle these
      notifications. <span class="command"><strong>udev</strong></span> manages the dynamic
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev</code></html:span> directory as well.
    </p>

    <p>
      The mode of operation of <span class="command"><strong>udev</strong></span> for handling
      hotplugging of devices is fairly simple. When a device is added
      to the system, the kernel notifies userspace hotplug event
      listeners. <span class="command"><strong>udev</strong></span> will receive the notification
      of the device being added, and looks whether there are any
      module mappings for the device. If there are, the appropriate
      device driver module for the device is automatically
      loaded. <span class="command"><strong>udev</strong></span> will remove the module when it
      is notified of a device removal, and no devices use the loaded
      module anymore.
    </p>

    <p>
      The udev subsystem is initialized in
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.S</code></html:span> by executing
      <span class="command"><strong>/etc/rc.d/rc.udev start</strong></span>. As with most
      functionality, you can enable or disable udev by twiddling the
      executable flag of the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.udev</code></html:span>
      script (see <a class="xref" href="#chap-init-initscripts" title="19.3. Initialization scripts">Section 19.3, “Initialization scripts”</a>).
    </p>

    <p>
      If udev automatically loads modules that you do not want to
      load, you can add a <span class="emphasis"><em>blacklist</em></span> in your
      <span class="command"><strong>modprobe</strong></span> configuration in
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/modprobe.d/blacklist</code></html:span>. For example, if
      you would like to prevent loading of the
      <span class="emphasis"><em>8139cp</em></span> module, you can add the following
      line (actually, this module is already blacklisted in Slackware
      Linux):
    </p>

    <pre class="screen">
blacklist 8139cp
    </pre>
  </div>

  <div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-init-firmware"></a>19.5. Device firmware</h2></div></div></div>
    

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-init-firmware-introduction"></a>19.5.1. Introduction</h3></div></div></div>
      

      <p>
	Some hardware requires the system to upload firmware. Firmware
	is a piece of software that is used to control the hardware.
	Traditionally, the firmware was stored permanently in ROM
	(read-only memory) or non-volatile media like flash memory.
	However, many new devices use volatile memory to store
	firmware, meaning that the firmware needs to be reloaded to
	the device memory when the system is restarted.
      </p>

      <p>
	Drivers for devices that require firmware have a table of the
	firmware files that it needs. For each firmware file that the
	driver needs, it will issue a firmware addition event. If udev
	handles hotplugging events, it will try to handle that event.
	The udev rules contain an entry for firmware addition events
	in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/udev/rules.d/50-udev.rules</code></html:span>:
      </p>

      <pre class="programlisting">
# firmware loader
SUBSYSTEM=="firmware", ACTION=="add", RUN+="/lib/udev/firmware.sh"
      </pre>

      <p>
	This means that upon firmware addition events, the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/lib/udev/firmware.sh</code></html:span> script should be
	executed. This script searches the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/lib/firmware</code></html:span> and
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/usr/local/lib/firmware</code></html:span> directories for
	the requested firmware. If the firmware file exists, it will
	be loaded by copying the contents of the file to a special
	sysfs node.
      </p>
    </div>

    <div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-init-firmware-adding"></a>19.5.2. Adding firmware</h3></div></div></div>
      

      <p>
	As described in the previous section, some hardware requires
	firmware to be uploaded to hardware by the operating system.
	If this is the case, and no firmware is installed, the kernel
	will emit an error message when the driver for that hardware
	is loaded. You can see the kernel output with the
	<span class="command"><strong>dmesg</strong></span> command or in the
	<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var/log/messages</code></html:span> log file. Such error
	message explicitly says that the firmware could not be loaded,
	for example:
      </p>

      <pre class="screen">
ipw2100: eth1: Firmware 'ipw2100-1.3.fw' not available or load failed.
ipw2100: eth1: ipw2100_get_firmware failed: -2 
      </pre>

      <p>
	In this case you will have to find the firmware for your
	device. This can usually be found by searching the web for the
	chipset or driver for the device (in this case
	<span class="emphasis"><em>ipw2100</em></span>) and the literal term
	<span class="quote">“<span class="quote">firmware</span>”</span>. The firmware archive often contains a
	file with installation instructions. Usually you can just copy
	the firmware files to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/lib/firmware</code></html:span>.
      </p>

      <p>
	After installing the firmware, you can reload the driver with
	<span class="command"><strong>rmmod</strong></span> and <span class="command"><strong>modprobe</strong></span>, or
	by restarting the system.
      </p>
    </div>
  </div>


</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="idm950258444"></a>Chapter 20. Security</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#idm950258188">20.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950256916">20.2. Closing services</a></span></dt>
</dl>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950258188"></a>20.1. Introduction</h2></div></div></div>
<p>
With the increasing usage of the Internet and wireless networks security
is getting more important every day. It is impossible to cover this subject
in a single chapter of an introduction to GNU/Linux. This chapter covers
some basic security techniques that provide a good start for desktop
and server security.
</p>
<p>
Before we go on to specific subjects, it is a good idea to make some remarks
about passwords. Computer authorization largely relies on passwords. Be
sure to use good passwords in all situations. Avoid using words, names,
birth dates and short passwords. These passwords can easily be cracked
with dictionary attacks or brute force attacks against hosts or password
hashes. Use long passwords, ideally eight characters or longer, consisting
of random letters (including capitals) and numbers.
</p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950256916"></a>20.2. Closing services</h2></div></div></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950256724"></a>20.2.1. Introduction</h3></div></div></div>
<p>
Many GNU/Linux run some services that are open to a local network or the
Internet. Other hosts can connect to these services by connecting to specific
ports. For example, port 80 is used for WWW traffic. The
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/services</code></html:span> file contains a table with all commonly
used services, and the port numbers that are used for these services.
</p>
<p>
A secure system should only run the services that are necessary. So, suppose
that a host is acting as a web server, it should not have ports open (thus
servicing) FTP or SMTP. With more open ports security risks increase very
fast, because there is a bigger chance that the software servicing a port
has a vulnerability, or is badly configured. The following few sections
will help you tracking down which ports are open, and closing them.
</p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950255188"></a>20.2.2. Finding open ports</h3></div></div></div>
<p>
Open ports can be found using a port scanner. Probably the most famous 
port scanner for GNU/Linux is <span class="command"><strong>nmap</strong></span>. <span class="command"><strong>nmap</strong></span>
is available through the <span class="quote">“<span class="quote">n</span>”</span> disk set. 
</p>
<p>
The basic <span class="command"><strong>nmap</strong></span> syntax is: <span class="command"><strong>nmap host</strong></span>. The
<span class="emphasis"><em>host</em></span> parameter can either be a hostname or IP address.
Suppose that we would like to scan the host that <span class="command"><strong>nmap</strong></span>
is installed on. In this case we could specify the 
<span class="emphasis"><em>localhost</em></span> IP address, <span class="emphasis"><em>127.0.0.1</em></span>:
</p>
<pre class="screen">
$ <span class="command"><strong>nmap 127.0.0.1</strong></span>

Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Interesting ports on localhost (127.0.0.1):
(The 1596 ports scanned but not shown below are in state: closed)
Port       State       Service
21/tcp     open        ftp                     
22/tcp     open        ssh                     
23/tcp     open        telnet                  
80/tcp     open        http                    
6000/tcp   open        X11                     

Nmap run completed -- 1 IP address (1 host up) scanned in 0 seconds
</pre>
<p>
In this example you can see that the host has five open ports that are
being serviced; ftp, ssh, telnet, http and X11.
</p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950251292"></a>20.2.3. inetd</h3></div></div></div>
<p>
There are two ways to offer TCP/IP services: by running server
applications  stand-alone as a daemon or by using the internet super
server, <span class="command"><strong>inetd</strong></span>. inetd  is a daemon which monitors
a range of ports. If a client attempts to connect  to a port inetd
handles the connection and forwards the connection to the  server
software which handles that kind of connection. The advantage of this
approach is that it adds an extra layer of security and it makes it
easier to  log incoming connections. The disadvantage is that it is
somewhat slower than  using a stand-alone daemon. It is thus a good
idea to run a stand-alone daemon on, for example, a heavily loaded FTP
server.
</p>
<p>
You can check whether <span class="command"><strong>inetd</strong></span> is running on a host or
not with <span class="command"><strong>ps</strong></span>, for example:
</p>
<pre class="screen">
$ <span class="command"><strong>ps ax | grep inetd</strong></span>
 2845 ?        S      0:00 /usr/sbin/inetd
</pre>
<p>
In this example inetd is running with PID (process ID) 2845. 
<span class="command"><strong>inetd</strong></span> can be configured using the
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/inetd.conf</code></html:span> file. Let's have a look at an example 
line from inetd.conf:
</p>
<pre class="screen">
# File Transfer Protocol (FTP) server:
ftp     stream  tcp     nowait  root    /usr/sbin/tcpd  proftpd
</pre>
<p>
This line specifies that inetd should accept FTP connections and pass them to 
<span class="command"><strong>tcpd</strong></span>. This may seem a bit odd, because 
<span class="command"><strong>proftpd</strong></span> normally handles FTP connections. You can also 
specify to use proftpd directly in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">inetd.conf</code></html:span>, but 
it is a good idea to give the connection to <span class="command"><strong>tcpd</strong></span>. This 
program passes the connection to <span class="command"><strong>proftpd</strong></span> in turn, as 
specified. <span class="command"><strong>tcpd</strong></span> is used to monitor services and to provide 
host based access control. 
</p>
<p>
Services can be disabled by adding the comment character (#) at the beginning 
of the line. It is a good idea to disable all services and enable services you 
need one at a time. After changing <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/inetd.conf</code></html:span> 
<span class="command"><strong>inetd</strong></span> needs to be restarted to activate the changes. This 
can be done by sending the HUP signal to the inetd process:
</p>
<pre class="screen">
# <span class="command"><strong>ps ax | grep 'inetd'</strong></span>
   2845 ?        S      0:00 /usr/sbin/inetd
# <span class="command"><strong>kill -HUP 2845</strong></span>
</pre>
<p>
If you do not need <span class="command"><strong>inetd</strong></span> at all, it is a good idea to
remove it. If you want to keep it installed, but do not want Slackware Linux
to load it at the booting process, execute the following command as root:
</p>
<pre class="screen">
# <span class="command"><strong>chmod a-x /etc/rc.d/rc.inetd</strong></span>
</pre>
</div>
</div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="sysadmin-misc"></a>Chapter 21. Miscel·lània</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#sysadmin-misc-cron">21.1. Planificant tasques amb cron </a></span></dt>
<dt><span class="sect1"><a href="#sysadmin-misc-hdparm">21.2. Paràmetres de disc dur </a></span></dt>
<dt><span class="sect1"><a href="#sysadmin-memory-hdparm">21.3. Monitorejant  l'ús de la memòria </a></span></dt>
</dl>
</div>
<div class="sect1">
<div class="titlepage"><div>
<div><h2 class="title" style="clear: both">
<a name="sysadmin-misc-cron"></a>21.1. Planificant tasques amb cron </h2></div>
<div><div class="authorgroup"><div class="author">
<h3 class="author">
<span class="firstname">Murray</span> <span class="surname">Stokely</span>
</h3>
<span class="contrib">Written by </span> </div></div></div>
</div></div>
<a class="indexterm" name="idm950241508"></a><a class="indexterm" name="idm950241316"></a><a class="indexterm" name="idm950241124"></a><p>
      Slackware Linux inclou una implementació del dimoni clàssic de
      UNIX cron que permet als usuaris planificar tasques per a que 
      s'executen a intervals regulars. Cada usuari pot crear, eliminar,
      o modificar un fitxer crontab individual. Aquest fitxer crontab
      especifica les ordres o guions a executar a intervals de temps
      especificats. Les línies en blanc al crontab o les línies que 
      començen amb un coixinet (<span class="quote">“<span class="quote"><code class="literal">#</code></span>”</span>)
      són ignorades.

      </p>
<p>
      Cada entrada en el fitxer crontab ha de contindre 6 camps
      separats per espais. Aquests camps són minut, hora, dia, mes,
      dia de la setmana, i ordre. Cadascún dels primers cinc camps
      haurien de contindre un temps o el caràcter comodí 
      <span class="quote">“<span class="quote"><code class="literal">*</code></span>”</span> per a coincidir amb tots els
      temps per a eixe camp. Per exemple, per a tindre la ordre
      <span class="command"><strong>date</strong></span> executada cada dia a les 6:10, es
      pordia utilitzat la següent entrada.

      </p>
<pre class="programlisting">10 6 * * * date</pre>
<p>
      Un crontab d'usuari es pot visualitzar amb la ordre
      <span class="command"><strong>crontab -l</strong></span>. Per a una introducció més 
      a fons a la sintaxi del fitxer crontab, examinem el crontab
      per defecte de l'usuari root.
      </p>
<pre class="screen"># <strong class="userinput"><code>crontab -l</code></strong>
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system, but if they don't the average newbie
# might get quite perplexed about getting strange mail every 5 minutes. :^)
#
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this.  If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
#
# Run hourly cron jobs at 47 minutes after the hour:
47<a name="co-crontab-1"></a><span><img src="../images/callouts/1.png" alt="1" border="0"></span> *<a name="co-crontab-2"></a><span><img src="../images/callouts/2.png" alt="2" border="0"></span> *<a name="co-crontab-3"></a><span><img src="../images/callouts/3.png" alt="3" border="0"></span> *<a name="co-crontab-4"></a><span><img src="../images/callouts/4.png" alt="4" border="0"></span> *<a name="co-crontab-5"></a><span><img src="../images/callouts/5.png" alt="5" border="0"></span> /usr/bin/run-parts /etc/cron.hourly 1&gt; /dev/null<a name="co-crontab-6"></a><span><img src="../images/callouts/6.png" alt="6" border="0"></span>
#
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1&gt; /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1&gt; /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1&gt; /dev/null</pre>
<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-crontab-1"><span><img src="../images/callouts/1.png" alt="1" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
	  El primer camp, <code class="literal">47</code>, especifica que este
	  treball s'huaria de fer 47 minuts després de l'hora.
	  </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-crontab-2"><span><img src="../images/callouts/2.png" alt="2" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
	  El segon camp, <code class="literal">*</code>, és una comodí, pel que 
	  aquest treball hauria d'ocórrer <span class="emphasis"><em>cada</em></span> hora.
	  </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-crontab-3"><span><img src="../images/callouts/3.png" alt="3" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
	  El tercer camp, <code class="literal">*</code>, és un comodí,
	  pel que aquest treball hauria d'ocórrer <span class="emphasis"><em>cada
	</em></span> dia.
	  </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-crontab-4"><span><img src="../images/callouts/4.png" alt="4" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
	  El quart camp, <code class="literal">*</code>, és un comodí,
	  pel que aquest treball hauria d'ocórrer <span class="emphasis"><em>cada
	</em></span> mes.
	</p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-crontab-5"><span><img src="../images/callouts/5.png" alt="5" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
	  El cinqué camp, <code class="literal">*</code>, és un comodí,
	  pel que aquest treball hauria d'ocórrer <span class="emphasis"><em>cada</em></span> 
	  dia de la setmana.
	  </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a href="#co-crontab-6"><span><img src="../images/callouts/6.png" alt="6" border="0"></span></a> </p></td>
<td valign="top" align="left"><p>
	  El sisé camp, <span class="command"><strong>/usr/bin/run-parts /etc/cron.hourly 1&gt; 
	  /dev/null</strong></span>, especifica la ordre que s'hauria d'executar
	  en el temps especificat en els primers cinc camps.
	  </p></td>
</tr>
</table></div>
<a class="indexterm" name="idm950227396"></a><a class="indexterm" name="idm950227092"></a><p>
      El crontab per defecte de root està configurat per a executar els 
      guions a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/cron.monthly</code></html:span> mensualment,
      els guions a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/cron.weekly</code></html:span> setmanalment,
      els que hi ha a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/cron.daily</code></html:span> diàriament,
      i els continguts a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/cron.hourly</code></html:span> cada hora.
      Per aquesta raó no és estrictament necessari per a un administrador
      comprendre el funcionament intern de cron. Amb Slackware Linux,
      pots senzillament, afegir un script nou a un dels directoris de
      dalt per a programar una tasca periòdica. De fet, fullejant eixos
      directoris et faràs una idea de la feina que Slackware Linux fa
      regularment fora d'escena per a mantidre coses com la base de dades
      <span class="command"><strong>slocate</strong></span> actualitzades.

      </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sysadmin-misc-hdparm"></a>21.2. Paràmetres de disc dur </h2></div></div></div>
<a class="indexterm" name="idm950223652"></a><a class="indexterm" name="idm950223460"></a><p>
      La majoria de discs ofereixen vàries característiques per a
      incrementar el rendiment del disc i millorar la integritat. La
      majoria d'aquestes característiques es poden ajustar amb la ordre
      <span class="command"><strong>hdparm</strong></span>. Vés amb compte al canviar la configuració
      del disc amb aquesta utilitat, perque alguns canvis poden estropejar
      dades al teu disc.

      
    </p>
<p>
      Pots obtindre un resum de la configuració activa per a un disc
      proporcionanant-li el node de dispositiu d'un disc com a
      paràmetre a <span class="command"><strong>hdparm</strong></span>:
      
    </p>
<pre class="screen">
# <span class="command"><strong>hdparm /dev/hda</strong></span>

/dev/hda:
 multcount    =  0 (off)
 IO_support   =  1 (32-bit)
 unmaskirq    =  1 (on)
 using_dma    =  1 (on)
 keepsettings =  0 (off)
 readonly     =  0 (off)
 readahead    = 256 (on)
 geometry     = 65535/16/63, sectors = 78165360, start = 0
    </pre>
<p>
      Una raó comuna per a un rendiment baix de disc és que el DMA
      no és utilitzat automàticament pel núcli per a un disc. DMA
      accelerarà l'ample de banda de E/E (Entrada/Eixida) i disminueix
      l'ús del processador, fent possible la transmissió directa de 
      dades des del disc a la memòria del sistema. Si el DMA s'apaga,
      el resum de la configuració mostraria aquesta línia:

      
    </p>
<pre class="screen">
using_dma    =  0 (off)
    </pre>
<p>
      Pots encendre el DMA fàcilment per a aquest disc amb el 
      paràmetre <em class="parameter"><code>-d</code></em> de
      <span class="command"><strong>hdparm</strong></span>:
      
    </p>
<pre class="screen">
# <span class="command"><strong>hdparm -d 1 /dev/hda</strong></span>

/dev/hda:
 setting using_dma to 1 (on)
 using_dma    =  1 (on)
    </pre>
<p>
      Pots fer açò durant cada inici afegint la ordre
      hdparm a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.local</code></html:span>.
      
    </p>
<p>
      El paràmetre <em class="parameter"><code>-i</code></em> de
      <span class="command"><strong>hdparm</strong></span> és també molt útilm, perque ofereix
      informació detallada del disc:

      
    </p>
<pre class="screen">
# <span class="command"><strong>hdparm -i /dev/hda</strong></span>
/dev/hda:

 Model=WDC WD400EB-00CPF0, FwRev=06.04G06, SerialNo=WD-WCAAT6022342
 Config={ HardSect NotMFM HdSw&gt;15uSec SpinMotCtl Fixed DTR&gt;5Mbs FmtGapReq }
 RawCHS=16383/16/63, TrkSize=57600, SectSize=600, ECCbytes=40
 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=off
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=78163247
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio1 pio2 pio3 pio4 
 DMA modes:  mdma0 mdma1 mdma2 
 UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5 
 AdvancedPM=no WriteCache=enabled
 Drive conforms to: device does not report version: 

 * signifies the current active mode
    </pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sysadmin-memory-hdparm"></a>21.3. Monitorejant  l'ús de la memòria </h2></div></div></div>
<p>
      En algunes situacions rsulta d'utilitat ls informació de diagnòstic
      referent a com s'utilitza la memòria. Per exemple, en un servidor
      amb mal rendiment podries voler veurer si la escassetat de memòria està 
      causant que el sistema emmagatzeme pàgines a la memòria swap, o potser
      estàs posant en marxa un servei de xarxa, i vols trobar els
      paràmetres òptims per a la memòria cau. Slackware Linux 
      propociona algunes eines que t'ajudaràn a analitzar com s'utilitza
      la memòria.

      
    </p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="sysadmin-misc-memory-vmstat"></a>21.3.1. vmstat</h3></div></div></div>
<p>
	<span class="command"><strong>vmstat</strong></span> és una ordre que proporciona
	estadístiques sobre vàries parts de la memòria virtual del
	sistema. Executat sense paràmetres <span class="command"><strong>vmstat</strong></span>
	proporciona un resum d'algunes estadístiques relevants:
        
      </p>
<pre class="screen">
# <span class="command"><strong>vmstat</strong></span>
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0      0 286804   7912  98632    0    0   198     9 1189   783  5  1 93  1
      </pre>
<p>
	Com només estem mirant l'ús de memòria en aquesta secció, només
	ens fixarem en els camps <span class="emphasis"><em>memory</em></span> i
        <span class="emphasis"><em>swap</em></span>
        
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
            <span class="emphasis"><em>swpd</em></span>: La quantitat de memòria virtual
	    sent utilitzada.
	    
          </p></li>
<li class="listitem"><p>
            <span class="emphasis"><em>free</em></span>: La quantitat de memòria 
	    lliure en eixe moment.

          </p></li>
<li class="listitem"><p>
            <span class="emphasis"><em>buff</em></span>: La quantitat de memòria 
	    utilitzada com a buffers.

          </p></li>
<li class="listitem"><p>
            <span class="emphasis"><em>cache</em></span>: La quantitat de memòria
	    utilitzada com a cau.

          </p></li>
<li class="listitem"><p>
            <span class="emphasis"><em>si</em></span>: La quantitat de memòria que
	    és intercanviada des del disc per segon.

          </p></li>
<li class="listitem"><p>
            <span class="emphasis"><em>so</em></span>: La quantitat de memòria que
	    és intercanviada cap al disc per segon.

          </p></li>
</ul></div>
<p>
	Sol ser d'utilitat veurer com l'ús de la memòria canvia al llarg
	del temps. Pots afegir un interval com a paràmetre a 
	<span class="command"><strong>vmstat</strong></span> per a que aquest s'execute contínuament, 
	imprimint les estadístiques actuals. Aquest interval és en segons,
	així que, si vols obtindre estadístiques cada segon, pots executar:

        
      </p>
<pre class="screen">
# <span class="command"><strong>vmstat 1</strong></span>
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 2  0      0 315132   8832  99324    0    0   189    10 1185   767  5  1 93  1
 1  0      0 304812   8832  99324    0    0     0     0 1222  6881 24  8 68  0
 0  0      0 299948   8836  99312    0    0     0     0 1171  1824 41  9 49  0
 [...]
      </pre>
<p>
	Addicionalment, pots dir-li a <span class="command"><strong>vmstat</strong></span> cuantes vegades
	hauria de mostrar les estadístiques (enlloc de fer-ho sense fi).
	Per exemple, si volguéres imprimir estes estadístiques cada dos segons,
	i cinc vegades en total, podries executar <span class="command"><strong>vmstat</strong></span> de
	la següent manera:

        
      </p>
<pre class="screen">
# <span class="command"><strong>vmstat 2 5</strong></span>
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 2  0      0 300996   9172  99360    0    0   186    10 1184   756  5  1 93  1
 0  1      0 299012   9848  99368    0    0   336     0 1293  8167 20  8 21 51
 1  0      0 294788  11976  99368    0    0  1054     0 1341 12749 14 11  0 76
 2  0      0 289996  13916  99368    0    0   960   176 1320 17636 22 14  0 64
 2  0      0 284620  16112  99368    0    0  1086   426 1351 21217 25 18  0 58
      </pre>
</div>
</div>
</div>
   </div>

  <div class="part">
<div class="titlepage"><div><div><h1 class="title">
<a name="netadmin"></a>Part VI. Administració de xarxa</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="chapter"><a href="#sysadmin-netconfig">22. Networking configuration</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#sysadmin-netconfig-hardware">22.1. Hardware</a></span></dt>
<dt><span class="sect1"><a href="#idm950197876">22.2. Configuration of interfaces</a></span></dt>
<dt><span class="sect1"><a href="#idm950191964">22.3. Configuration of interfaces (IPv6)</a></span></dt>
<dt><span class="sect1"><a href="#idm950179556">22.4. Wireless interfaces</a></span></dt>
<dt><span class="sect1"><a href="#idm950179492">22.5. Resolving</a></span></dt>
<dt><span class="sect1"><a href="#idm950170580">22.6. IPv4 Forwarding</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#ipsec">23. IPsec</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950156644">23.1. Theory</a></span></dt>
<dt><span class="sect1"><a href="#idm950151132">23.2. Linux configuration</a></span></dt>
<dt><span class="sect1"><a href="#idm950147732">23.3. Installing IPsec-Tools</a></span></dt>
<dt><span class="sect1"><a href="#idm950142780">23.4. Setting up IPsec with manual keying</a></span></dt>
<dt><span class="sect1"><a href="#idm950129420">23.5. Setting up IPsec with automatic key exchanging</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#idm950106380">24. The Internet super server</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950106060">24.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950104412">24.2. Configuration</a></span></dt>
<dt><span class="sect1"><a href="#idm950098324">24.3. TCP wrappers</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#idm950091836">25. Apache</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950091548">25.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950090932">25.2. Installation</a></span></dt>
<dt><span class="sect1"><a href="#idm950085940">25.3. User directories</a></span></dt>
<dt><span class="sect1"><a href="#idm950083380">25.4. Virtual hosts</a></span></dt>
</dl></dd>
<dt><span class="chapter"><a href="#idm950077628">26. BIND</a></span></dt>
<dd><dl>
<dt><span class="sect1"><a href="#idm950077340">26.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950069932">26.2. Making a caching nameserver</a></span></dt>
</dl></dd>
</dl>
</div>
    
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="sysadmin-netconfig"></a>Chapter 22. Networking configuration</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#sysadmin-netconfig-hardware">22.1. Hardware</a></span></dt>
<dt><span class="sect1"><a href="#idm950197876">22.2. Configuration of interfaces</a></span></dt>
<dt><span class="sect1"><a href="#idm950191964">22.3. Configuration of interfaces (IPv6)</a></span></dt>
<dt><span class="sect1"><a href="#idm950179556">22.4. Wireless interfaces</a></span></dt>
<dt><span class="sect1"><a href="#idm950179492">22.5. Resolving</a></span></dt>
<dt><span class="sect1"><a href="#idm950170580">22.6. IPv4 Forwarding</a></span></dt>
</dl>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sysadmin-netconfig-hardware"></a>22.1. Hardware</h2></div></div></div>
<h3>
<a name="idm950200876"></a>Network cards (NICs)</h3>
<p>
Drivers for NICs are installed as kernel modules. The module for
your NIC has to be loaded during the initialization of Slackware Linux.
On most systems the NIC is automatically detected and configured
during the installation of Slackware Linux. You can reconfigure
your NIC with the <span class="command"><strong>netconfig</strong></span> command.
<span class="command"><strong>netconfig</strong></span> adds the driver (module) for the detected
card to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.netdevice</code></html:span>. 
</p>
<p>
It is also possible to manually configure which modules should be
loaded during the initialization of the system. This can be done
by adding a <span class="command"><strong>modprobe</strong></span> line to
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.modules</code></html:span>. For example, if you want
to load the module for 3Com 59x NICs (3c59x.o), add the following
line to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.modules</code></html:span> 
</p>
<pre class="screen">
/sbin/modprobe 3c59x
</pre>
<h3>
<a name="idm950198540"></a>PCMCIA cards</h3>
<p>
Supported PCMCIA cards are detected automatically by the PCMCIA
software. The pcmcia-cs packages from the <span class="quote">“<span class="quote">a</span>”</span> disk set provides
PCMCIA functionality for Slackware Linux.
</p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950197876"></a>22.2. Configuration of interfaces</h2></div></div></div>
<p>
Network cards are available under Linux through so-called <span class="quote">“<span class="quote">interfaces</span>”</span>.
The <span class="command"><strong>ifconfig</strong></span> command can be used to display the
available interfaces:
</p>
<pre class="screen">
# <span class="command"><strong>ifconfig -a</strong></span>
eth0      Link encap:Ethernet  HWaddr 00:20:AF:F6:D4:AD  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1301 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1529 errors:0 dropped:0 overruns:0 carrier:0
          collisions:1 txqueuelen:100 
          RX bytes:472116 (461.0 Kb)  TX bytes:280355 (273.7 Kb)
          Interrupt:10 Base address:0xdc00 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:77 errors:0 dropped:0 overruns:0 frame:0
          TX packets:77 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:8482 (8.2 Kb)  TX bytes:8482 (8.2 Kb)
</pre>
<p>
Network cards get the name ethn, in which n is a number, starting with
0. In the example above, the first network card (eth0) already has an
IP address. But unconfigured interfaces have no IP address, the
<span class="command"><strong>ifconfig</strong></span> will not show IP addresses for unconfigured
interfaces. Interfaces can be configured in the 
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.inet1.conf</code></html:span> file. You can simply read
the comments, and fill in the required information. For example:
</p>
<pre class="screen">
# Config information for eth0:
IPADDR[0]="192.168.1.1"
NETMASK[0]="255.255.255.0"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""
</pre>
<p>
In this example the IP address 192.168.1.1 with the 255.255.255.0
netmask is assigned to the first ethernet interface (eth0). If you
are using a DHCP server you can change the <span class="emphasis"><em>USE_DHCP=""</em></span> 
line to <span class="emphasis"><em>USE_DHP[n]="yes"</em></span> (swap <span class="quote">“<span class="quote">n</span>”</span> with 
the interface number). Other variables, except <span class="emphasis"><em>DHCP_HOSTNAME</em></span>
are ignored when using DHCP. For example:
</p>
<pre class="screen">
IPADDR[1]=""
NETMASK[1]=""
USE_DHCP[1]="yes"
DHCP_HOSTNAME[1]=""
</pre>
<p>
The same applies to other interfaces. You can activate the settings
by rebooting the system or by executing <span class="command"><strong>/etc/rc.d/rc.inet1</strong></span>.
It is also possible to reconfigure only one interface with
<span class="command"><strong>/etc/rc.d/rc.inet1 ethX_restart</strong></span>, in which
<span class="emphasis"><em>ethX</em></span> should be replaced by the name of the interface
that you would like to reconfigure.
</p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950191964"></a>22.3. Configuration of interfaces (IPv6)</h2></div></div></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950191732"></a>22.3.1. Introduction</h3></div></div></div>
<p>
<acronym class="acronym">IPv6</acronym> is the next generation internet protocol. One
of  the advantages is that it has a much larger address space. In IPv4
(the internet protocol that is commonly used today) addresses are
32-bit, this address space is almost completely used right now, and
there is a lack of IPv4 addresses.  IPv6 uses 128-bit addresses, which
provides an unimaginable huge address space (2^128 addresses). IPv6
uses another address notation, first of all hex numbers are used
instead of decimal numbers, and the address is noted in pairs of
16-bits, separated by a colon (<span class="quote">“<span class="quote">:</span>”</span>).  Let's have a look
at an example address: </p>
<pre class="screen">
fec0:ffff:a300:2312:0:0:0:1
</pre>
<p>
A block of zeroes can be replaced by two colons (<span class="quote">“<span class="quote">::</span>”</span>). Thus,
the address above can be written as:
</p>
<pre class="screen">
fec0:ffff:a300:2312::1
</pre>
<p>
Each IPv6 address has a prefix. Normally this consists of two elements:
32 bits identifying the address space the provider provides you, and a
16-bit number that specifies the network. These two elements form the
prefix, and in this case the prefix length is 32 + 16 = 48 bits. Thus,
if you have a /48 prefix you can make 2^16 subnets and have 2^80 hosts
on each subnet. The image below shows the structure of an IPv6 address
with a 48-bit prefix.
</p>
<div class="figure">
<a name="ipv6address"></a><p class="title"><b>Figure 22.1. The anatomy of an IPv6 address</b></p>
<div class="figure-contents"><div class="mediaobject"><img src="../../images/ipv6addr.png" alt="The anatomy of an IPv6 address"></div></div>
</div>
<br class="figure-break"><p>
There are a some specially reserved prefixes, most notable include:
</p>
<div class="table">
<a name="idm950187636"></a><p class="title"><b>Table 22.1. Important IPv6 Prefixes</b></p>
<div class="table-contents"><table summary="Important IPv6 Prefixes" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Prefix</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td>fe80::</td>
<td>Link local addresses, which are not routed.</td>
</tr>
<tr>
<td>fec0::</td>
<td>Site local addresses, which are locally routed, but not on or to the internet.</td>
</tr>
<tr>
<td>2002::</td>
<td>6to4 addresses, which are used for the transition from IPv4 to IPv6.</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950185540"></a>22.3.2. Slackware Linux IPv6 support</h3></div></div></div>
<p>
The Linux kernel binaries included in Slackware Linux do not support IPv6
by default, but support is included as a kernel module. This module can be
loaded using <span class="command"><strong>modprobe</strong></span>:
</p>
<pre class="screen">
# <span class="command"><strong>modprobe ipv6</strong></span>
</pre>
<p>
You can verify if IPv6 support is loaded correctly by looking at the 
kernel output using the <span class="command"><strong>dmesg</strong></span>:
</p>
<pre class="screen">
$ <span class="command"><strong>dmesg</strong></span>
[..]
IPv6 v0.8 for NET4.0
</pre>
<p>
IPv6 support can be enabled permanently by adding the following line to
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.modules</code></html:span>:
</p>
<pre class="screen">
/sbin/modprobe ipv6
</pre>
<p>
Interfaces can be configured using <span class="command"><strong>ifconfig</strong></span>. But it
is recommended to make IPv6 settings using the <span class="command"><strong>ip</strong></span>
command, which is part of the <span class="quote">“<span class="quote">iputils</span>”</span> package that can
be found in the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">extra/</code></html:span> directory of the Slackware Linux 
tree.
</p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950181908"></a>22.3.3. Adding an IPv6 address to an interface</h3></div></div></div>
<p>
If there are any router advertisers on a network there is a chance
that the interfaces on that network already received an IPv6 address
when the IPv6 kernel support was loaded. If this is not the case
an IPv6 address can be added to an interface using the <span class="command"><strong>ip</strong></span>
utility. Suppose we want to add the address <span class="quote">“<span class="quote">fec0:0:0:bebe::1</span>”</span>
with a prefix length of 64 (meaning <span class="quote">“<span class="quote">fec0:0:0:bebe</span>”</span> is the 
prefix). This can be done with the following command syntax:
</p>
<pre class="screen">
# <span class="command"><strong>ip -6 addr add &lt;ip6addr&gt;/&lt;prefixlen&gt; dev &lt;device&gt;</strong></span>
</pre>
<p>
For example:
</p>
<pre class="screen">
# <span class="command"><strong>ip -6 addr add fec0:0:0:bebe::1/64 dev eth0</strong></span>
</pre>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950179556"></a>22.4. Wireless interfaces</h2></div></div></div>
<p>
Wireless interfaces usually require some additional configuration, like
setting the ESSID, WEP keys and the wireless mode. Interface settings that
are specific to wireless interfaces can be set in the 
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.wireless.conf</code></html:span> file. The
<span class="command"><strong>/etc/rc.d/rc.wireless</strong></span> script configures wireless
interfaces based on descriptions from
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.wireless.conf</code></html:span>. In
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">rc.wireless.conf</code></html:span> settings are made per interface
MAC address. By default this file has a section that matches any interface:
</p>
<pre class="screen">
## NOTE : Comment out the following five lines to activate the samples below ...
## --------- START SECTION TO REMOVE -----------
## Pick up any Access Point, should work on most 802.11 cards
*)
    INFO="Any ESSID"
    ESSID="any"
    ;;
## ---------- END SECTION TO REMOVE ------------
</pre>
<p>
It is generally a good idea to remove this section to make per-card
settings. If you are lazy and only have one wireless card, you can leave
this section in and add any configuration parameters you need. Since this
section matches any wireless interface the wireless card you have will
be matched and configured. You can now add a sections for your wireless
interfaces. Each section has the following format:
</p>
<pre class="screen">
&lt;MAC address&gt;)
    &lt;settings&gt;
;;
</pre>
<p>
You can find the MAC address of an interface by looking at the 
<span class="command"><strong>ifconfig</strong></span> output for the interface. For example,
if a wireless card has the <span class="emphasis"><em>eth1</em></span> interface name,
you can find the MAC address the following way:
</p>
<pre class="screen">
# <span class="command"><strong>ifconfig eth1</strong></span>
eth1      Link encap:Ethernet  HWaddr <span class="emphasis"><em>00:01:F4:EC:A5:32</em></span>
          inet addr:192.168.2.2  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:1 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:504 (504.0 b)
          Interrupt:5 Base address:0x100
</pre>
<p>
The hexadecimal address that is printed after <span class="emphasis"><em>HWaddr</em></span>
is the MAC address, in this case <span class="emphasis"><em>00:01:F4:EC:A5:32</em></span>.
When you have found the MAC address of the interface you can add a section
for the device to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.wireless.conf</code></html:span>. For
example:
</p>
<pre class="screen">
00:01:F4:EC:A5:32)
    INFO="Cabletron Roamabout WLAN NIC"
    ESSID="home"
    CHANNEL="8"
    MODE="Managed"
    KEY="1234-5678-AB"
    ;;
</pre>
<p>
This will set the interface with MAC address
<span class="emphasis"><em>00:01:F4:EC:A5:32</em></span> to use the ESSID
<span class="emphasis"><em>home</em></span>, work in <span class="emphasis"><em>Managed</em></span> mode on
channel <span class="emphasis"><em>8</em></span>. The key used for WEP encryption is
<span class="emphasis"><em>1234-5678-AB</em></span>. There are many other parameters
that can be set. For an overview of all parameters, refer to the last
example in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">rc.wireless.conf</code></html:span>.
</p>
<p>
After configuring a wireless interface, you can activate the changes
by executing the network initialization script
<span class="command"><strong>/etc/rc.d/rc.inet1</strong></span>. You can see the current wireless
settings with the <span class="command"><strong>iwconfig</strong></span> command:
</p>
<pre class="screen">
eth1      IEEE 802.11-DS  ESSID:"home"  Nickname:"HERMES I"
          Mode:Managed  Frequency:2.447 GHz  Access Point: 02:20:6B:75:0C:56   
          Bit Rate:2 Mb/s   Tx-Power=15 dBm   Sensitivity:1/3  
          Retry limit:4   RTS thr:off   Fragment thr:off
          Encryption key:1234-5678-AB
          Power Management:off
          Link Quality=0/92  Signal level=134/153  Noise level=134/153
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:27  Invalid misc:0   Missed beacon:0
</pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950179492"></a>22.5. Resolving</h2></div></div></div>
<h3>
<a name="idm950170364"></a>Hostname</h3>
<p>
Each computer on the internet has a hostname. If you do not have a
hostname that is resolvable with DNS, it is still a good idea to
configure your hostname, because some software uses it. You can
configure the hostname in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/HOSTNAME</code></html:span>.
A single line with the hostname of the machine will suffice. Normally
a hostname has the following form: host.domain.tld, for example
darkstar.slackfans.org. Be aware that the hostname has to be resolvable,
meaning that GNU/Linux should be able to convert the hostname to an IP
address. You can make sure the hostname is resolvable by adding it
to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts</code></html:span>. Read the following section for
more information about this file.
</p>
<h3>
<a name="idm950168988"></a>/etc/hosts</h3>
<p>
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts</code></html:span> is a table of IP addresses with
associated hostnames. This file can be used to name computers
in a small network. Let's look at an example of the
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts</code></html:span> file:
</p>
<pre class="screen">
127.0.0.1               localhost
192.168.1.1             tazzy.slackfans.org tazzy
192.168.1.169           flux.slackfans.org
</pre>
<p>
The <span class="emphasis"><em>localhost</em></span> line should always be present. It assigns the name <span class="emphasis"><em>localhost</em></span>
to a special interface, the loopback. In this example the names
<span class="emphasis"><em>tazzy.slackfans.org</em></span> and <span class="emphasis"><em>tazzy</em></span> are assigned to the IP address 192.168.1.1,
and the name <span class="emphasis"><em>flux.slackfans.org</em></span> is assigned to the IP address 192.168.1.169.
On the system with this file both computers are available via the
mentioned hostnames.
</p>
<p>
It is also possible to add IPv6 addresses, which will be used if your system
is configured for IPv6. This is an example of a <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts</code></html:span>
file with IPv4 and IPv6 entries: 
</p>
<pre class="screen">
# IPv4 entries
127.0.0.1               localhost
192.168.1.1             tazzy.slackfans.org tazzy
192.168.1.169           gideon.slackfans.org

# IPv6 entries
::1			localhost
fec0:0:0:bebe::2	flux.slackfans.org	
</pre>
<p>
Please note that <span class="quote">“<span class="quote">::1</span>”</span> is the default IPv6 loopback.
</p>
<h3>
<a name="idm950165020"></a>/etc/resolv.conf</h3>
<p>
The <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/resolv.conf</code></html:span> file is used to specify
which nameservers the system should use. A nameserver converts hostnames
to IP addresses. Your provider should have given you at least two name
name server addresses (DNS servers). You can add these nameservers
to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/resolv.conf</code></html:span> by adding the line
<span class="emphasis"><em>nameserver ipaddress</em></span> for each nameserver. For example: 
</p>
<pre class="screen">
nameserver 192.168.1.1
nameserver 192.168.1.169
</pre>
<p>
You can check wether the hostnames are tranlated correctly or not with
the <span class="command"><strong>host hostname</strong></span> command. Swap <span class="emphasis"><em>hostname</em></span> with an
existing hostname, for example the website of your internet service
provider.
</p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950170580"></a>22.6. IPv4 Forwarding</h2></div></div></div>
<p>
IPv4 forwarding connects two or more networks by sending packets
which arrive on one interface to another interface. This makes it
possible to let a GNU/Linux machine act as a router. For example, you
can connect multiple networks, or your home network with the internet.
Let's have a look at an example:
</p>
<div class="figure">
<a name="router"></a><p class="title"><b>Figure 22.2. Router example</b></p>
<div class="figure-contents"><div class="mediaobject"><img src="../../images/router.png" alt="Router example"></div></div>
</div>
<br class="figure-break"><p>
In the example there are two networks, 192.168.1.0 and 192.168.2.0. Three
hosts are connected to both network. One of these hosts is connected to
both networks with interfaces. The interface on the 192.168.1.0 network
has IP address 192.168.1.3, the interface on the 192.168.2.0 network has
IP address 192.168.2.3. If the host acts as a router between both networks
it forwards packets from the 192.168.1.0 network to the 192.168.2.0 network
and vise versa. Routing of normal IPv4 TCP/IP packages can be enabled
by enabling IPv4 forwarding.
</p>
<p>
IPv4 forwarding
can be enabled or disabled under Slackware Linux by changing the
executable bit of the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.ip_forward</code></html:span>
file. If the executable bit is set on this file, IP forwarding will
be enabled during the system boot, otherwise it will not. You can
check whether the executable bit is enabled with <span class="command"><strong>ls -l</strong></span>
(a description of the <span class="command"><strong>ls</strong></span> command can be found in
<a class="xref" href="#chap-filesystems-analyzing-listing" title="8.2.1. Listing files">Section 8.2.1, “Listing files”</a>). 
</p>
<p>
It is also possible to enable IPv4 forwarding on a running system
with the following command (0 disables forwarding, 1 enables forwarding):
</p>
<pre class="screen">
# <span class="command"><strong>echo 0 &gt; /proc/sys/net/ipv4/ip_forward</strong></span>
</pre>
<p>
Be cautious! By default there are no active packet filters. This means
that anyone can access other networks. Traffic can be filtered
and logged with the iptables kernel packet filter. Iptables can
be administrated through the <span class="command"><strong>iptables</strong></span> command.
NAT (Network Address Translation) is also a subset of iptables,
and can be controlled and enabled through the <span class="command"><strong>iptables</strong></span>
command. NAT makes it possible to <span class="quote">“<span class="quote">hide</span>”</span> a network behind one
IP address. This allows you to use the internet on a complete network
with only one IP address.
</p>
</div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="ipsec"></a>Chapter 23. IPsec</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#idm950156644">23.1. Theory</a></span></dt>
<dt><span class="sect1"><a href="#idm950151132">23.2. Linux configuration</a></span></dt>
<dt><span class="sect1"><a href="#idm950147732">23.3. Installing IPsec-Tools</a></span></dt>
<dt><span class="sect1"><a href="#idm950142780">23.4. Setting up IPsec with manual keying</a></span></dt>
<dt><span class="sect1"><a href="#idm950129420">23.5. Setting up IPsec with automatic key exchanging</a></span></dt>
</dl>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950156644"></a>23.1. Theory</h2></div></div></div>
<p>
      <acronym class="acronym">IPsec</acronym> is a standard for securing IP communication
      through authentication, and encryption. Besides that it can compress
      packets, reducing traffic.  The following protocols are part of the
      IPsec standard:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
          <acronym class="acronym">AH</acronym> (Authentication Header) provides authenticity
          guarantee for transported packets. This is done by checksumming the
          packages using a cryptographic algorithm. If the checksum is found to
          be correct by the receiver, the receiver can be assured that the 
	  packet is not modified, and that the packet really originated from 
	  the reported sender (provided that the keys are only known by the 
	  sender and receiver). 
        </p></li>
<li class="listitem"><p>
          <acronym class="acronym">ESP</acronym> (Encapsulating Security Payload) is used to
          encrypt packets. This makes the data of the packet confident, and
	  only readable by the host with the right decryption key.
        </p></li>
<li class="listitem"><p>
          <acronym class="acronym">IPcomp</acronym> (IP payload compression) provides
	  compression before a packet is encrypted. This is useful, because
	  encrypted data generally compresses worse than unencrypted data.
        </p></li>
<li class="listitem"><p>
          <acronym class="acronym">IKE</acronym> (Internet Key Exchange) provides the means to
          negotiate keys in secrecy. Please note that IKE is optional, keys can
          be configured manually.
        </p></li>
</ul></div>
<p>
      There are actually two modes of operation: <span class="emphasis"><em>transport
      mode</em></span> is used to encrypt normal connections between two 
      hosts, <span class="emphasis"><em>tunnel mode</em></span> encapsulates the original
      package in a new header. In this chapter we are going to look at the 
      transport mode, because the primary goal of this chapter is to show 
      how to set up a secure connection between two hosts.
    </p>
<p>
      There are also two major methods of authentication. You can use manual
      keys, or an Internet Key Exchange (IKE) daemon, like racoon, that 
      automatically exchanges keys securely between two hosts. In both cases
      you need to set up a policy in the Security Policy Database (SPD). This
      database is used by the kernel to decide what kind of security policy
      is needed to communicate with another host. If you use manual keying you
      also have to set up Security Association Database (SAD) entries, which
      specifies what encryption algorithmn and key should be used for secure
      communication with another host. If you use an IKE daemon the security
      associations are automatically established.
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950151132"></a>23.2. Linux configuration</h2></div></div></div>
<p>
      Native IPsec support is only available in Linux 2.6.x kernels.
      Earlier kernels have no native IPsec support. So, make sure that
      you have a 2.6.x kernel. The 2.6 kernel is available in
      Slackware Linux 10.0, 10.1, and 10.2 from the
      <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">testing</code></html:span> directory on CD2 of the Slackware
      Linux CD sets, or any of the official Slackware Linux mirrors.
      The 2.6 kernel is the default kernel since Slackware Linux 12.0.
      The default Slackware Linux 2.6 kernel has support for AH, ESP
      and IPcomp in for both IPv4 and IPv6. If you are compiling a
      custom kernel enable use at least the following options in your
      kernel configuration:
    </p>
<pre class="screen">
CONFIG_INET_AH=y
CONFIG_INET_ESP=y
CONFIG_INET_IPCOMP=y
    </pre>
<p>
      Or you can compile support for IPsec protocols as a module:
    </p>
<pre class="screen">
CONFIG_INET_AH=m
CONFIG_INET_ESP=m
CONFIG_INET_IPCOMP=m
    </pre>
<p>
      In this chapter we are only going to use AH and ESP transformations, but
      it is not a bad idea to enable IPComp transformation for further 
      configuration of IPsec. Besides support for the IPsec protocols, you
      have to compile kernel support for the encryption and hashing algorithms
      that will be used by AH or ESP. Linux or module support for these
      algorithms can be enabled by twiddling the various
      <span class="emphasis"><em>CONFIG_CRYPTO</em></span> options. It does not hurt to
      compile all ciphers and hash algorithms as a module. 
    </p>
<p>
      When you choose to compile IPsec support as a module, make sure
      that the required modules are loaded. For example, if you are going
      to use ESP for IPv4 connections, load the <span class="emphasis"><em>esp4</em></span>
      module.
    </p>
<p>
      Compile the kernel as usual and boot it.
    </p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950147732"></a>23.3. Installing IPsec-Tools</h2></div></div></div>
<p>
      The next step is to install the
      <a class="ulink" href="http://ipsec-tools.sourceforge.net" target="_top">IPsec-Tools</a>.
      These tools are ports of
      the <a class="ulink" href="http://www.kame.net" target="_top">KAME</a> IPsec utilities.
      Download the latest sources and unpack, configure and install them:
    </p>
<pre class="screen">
# <span class="command"><strong>tar jxf ipsec-tools-x.y.z.tar.bz2</strong></span>
# <span class="command"><strong>cd ipsec-tools-x.y.z</strong></span>
# <span class="command"><strong>CFLAGS="-O2 -march=i486 -mcpu=i686" \
  ./configure --prefix=/usr \
              --sysconfdir=/etc \
              --localstatedir=/var \
              --enable-hybrid \
              --enable-natt \
              --enable-dpd \
              --enable-frag \
              i486-slackware-linux</strong></span>
# <span class="command"><strong>make</strong></span>
# <span class="command"><strong>make install</strong></span>
    </pre>
<p>
        Replace <span class="emphasis"><em>x.y.z</em></span> with the version of the
	downloaded sources. The most notable flags that we specify
	during the configuration of the sources are:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
	    <span class="emphasis"><em>--enable-dpd</em></span>: enables
	    dead peer detection (DPD). DPD is a method for detecting
	    wether any of the hosts for which security associations
	    are set up is unreachable. When this is the case the
	    security associations to that host can be removed.
	  </p></li>
<li class="listitem"><p>
	    <span class="emphasis"><em>--enable-natt</em></span>: enables NAT traversal
	    (NAT-T). Since NAT alters the IP headers, this causes
	    problems for guaranteeing authenticity of a packet. NAT-T
	    is a method that helps overcoming this problem. Configuring
	    NAT-T is beyond the scope of this article.
	  </p></li>
</ul></div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950142780"></a>23.4. Setting up IPsec with manual keying</h2></div></div></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950142548"></a>23.4.1. Introduction</h3></div></div></div>
<p>
        We will use an example as the guideline for setting up an encrypted
        connection between two hosts. The hosts have the IP addresses 
        <span class="emphasis"><em>192.168.1.1</em></span> and <span class="emphasis"><em>192.168.1.169</em></span>.
        The <span class="quote">“<span class="quote">transport mode</span>”</span> of operation will be used with
        AH and ESP transformations and manual keys.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950141276"></a>23.4.2. Writing the configuration file</h3></div></div></div>
<p>
        The first step is to write a configuration file we will name
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/setkey.conf</code></html:span>. On the first host
        (192.168.1.1) the following <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/setkey.conf</code></html:span>
        configuration will be used:
      </p>
<pre class="screen">
#!/usr/sbin/setkey -f

# Flush the SAD and SPD
flush;
spdflush;

add 192.168.1.1 192.168.1.169 ah 0x200 -A hmac-md5 
0xa731649644c5dee92cbd9c2e7e188ee6;
add 192.168.1.169 192.168.1.1 ah 0x300 -A hmac-md5 
0x27f6d123d7077b361662fc6e451f65d8;

add 192.168.1.1 192.168.1.169 esp 0x201 -E 3des-cbc 
0x656c8523255ccc23a66c1917aa0cf30991fce83532a4b224;
add 192.168.1.169 192.168.1.1 esp 0x301 -E 3des-cbc
0xc966199f24d095f3990a320d749056401e82b26570320292

spdadd 192.168.1.1 192.168.1.169 any -P out ipsec
           esp/transport//require
           ah/transport//require;

spdadd 192.168.1.169 192.168.1.1 any -P in ipsec
           esp/transport//require
           ah/transport//require;
      </pre>
<p>
        The first line (a line ends with a <span class="quote">“<span class="quote">;</span>”</span>) adds a key
        for the header checksumming for packets coming from 192.168.1.1 
        going to 192.168.1.169. The second line does the same for packets
        coming from 192.168.1.169 to 192.168.1.1. The third and the fourth line
        define the keys for the data encryption the same way as the
        first two lines. Finally the <span class="quote">“<span class="quote">spadd</span>”</span> lines define
        two policies, namely packets going out from 192.168.1.1 to 192.168.1.169
        should be (require) encoded (esp) and <span class="quote">“<span class="quote">signed</span>”</span> with
        the authorization header. The second policy is for incoming packets
        and it is the same as outgoing packages.
      </p>
<p>
        Please be aware that you should not use these keys, but your own
        secretly kept unique keys. You can generate keys using the
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/random</code></html:span> device:
      </p>
<pre class="screen">
# <span class="command"><strong>dd if=/dev/random count=16 bs=1 | xxd -ps</strong></span>
      </pre>
<p>
        This command uses dd to output 16 bytes from 
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/dev/random</code></html:span>. Don't forget to add <span class="quote">“<span class="quote">0x</span>”</span>
        at the beginning of the line in the configuration files. You can use 
        the 16 byte (128 bits) for the hmac-md5 algorithm that is used for AH.
        The 3des-cbc algorithm that is used for ESP in the example should be fed 
        with a 24 byte (192 bits) key. These keys can be generated with:
      </p>
<pre class="screen">
# <span class="command"><strong>dd if=/dev/random count=24 bs=1 | xxd -ps</strong></span>
      </pre>
<p>
        Make sure that the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/setkey.conf</code></html:span> file can only
        be read by the root user. If normal users can read the keys IPsec
        provides no security at all. You can do this with:
      </p>
<pre class="screen">
# <span class="command"><strong>chmod 600 /etc/setkey.conf</strong></span>
      </pre>
<p>
        The same <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/setkey.conf</code></html:span> can be created on the
        192.168.1.169 host, with inverted <em class="parameter"><code>-P 
        in</code></em> and <em class="parameter"><code>-P out</code></em> options. So, 
        the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/setkey.conf</code></html:span> will look like this:
      </p>
<pre class="screen">
#!/usr/sbin/setkey -f

# Flush the SAD and SPD
flush;
spdflush;

add 192.168.1.1 192.168.1.169 ah 0x200 -A hmac-md5
0xa731649644c5dee92cbd9c2e7e188ee6;
add 192.168.1.169 192.168.1.1 ah 0x300 -A hmac-md5
0x27f6d123d7077b361662fc6e451f65d8;

add 192.168.1.1 192.168.1.169 esp 0x201 -E 3des-cbc
0x656c8523255ccc23a66c1917aa0cf30991fce83532a4b224;
add 192.168.1.169 192.168.1.1 esp 0x301 -E 3des-cbc
0xc966199f24d095f3990a320d749056401e82b26570320292

spdadd 192.168.1.1 192.168.1.169 any -P in ipsec
           esp/transport//require
           ah/transport//require;

spdadd 192.168.1.169 192.168.1.1 any -P out ipsec
           esp/transport//require
           ah/transport//require;
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950141212"></a>23.4.3. Activating the IPsec configuration</h3></div></div></div>
<p>
        The IPsec configuration can be activated with the 
	<span class="command"><strong>setkey</strong></span> command:
      </p>
<pre class="screen">
# <span class="command"><strong>setkey -f /etc/setkey.conf</strong></span>
      </pre>
<p>
        If you want to enable IPsec permanently you can add the following line
        to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.local</code></html:span> on both hosts:
      </p>
<pre class="screen">
/usr/sbin/setkey -f /etc/setkey.conf
      </pre>
<p>
        After configuring IPsec you can test the connection by running
        <span class="command"><strong>tcpdump</strong></span> and simultaneously pinging the other
        host. You can see if AH and ESP are actually used in the 
        <span class="command"><strong>tcpdump</strong></span> output:
      </p>
<pre class="screen">
# <span class="command"><strong>tcpdump -i eth0</strong></span>
tcpdump: listening on eth0
11:29:58.869988 terrapin.taickim.net &gt; 192.168.1.169: AH(spi=0x00000200,seq=0x40f): ESP(spi=0x00000201,seq=0x40f) (DF)
11:29:58.870786 192.168.1.169 &gt; terrapin.taickim.net: AH(spi=0x00000300,seq=0x33d7): ESP(spi=0x00000301,seq=0x33d7)
      </pre>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950129420"></a>23.5. Setting up IPsec with automatic key exchanging</h2></div></div></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950129172"></a>23.5.1. Introduction</h3></div></div></div>
<p>
        The subject of automatical key exchange is already touched shortly
	in the introduction of this chapter. Put simply, IPsec with IKE
	works in the following steps.
      </p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem"><p>
	    Some process on the host wants to connect to another host. The
	    kernel checks whether there is a security policy set up for
	    the other host. If there already is a security association
	    corresponding with the policy the connection can be made,
	    and will be authenticated, encrypted and/or compressed as defined
	    in the security association. If there is no security association,
	    the kernel will request a user-land IKE daemon to set up the
	    necessary security association(s).
	  </p></li>
<li class="listitem"><p>
	    During the first phase of the key exchange the IKE daemon
	    will try to verify the authenticity of the other host. This
	    is usually done with a preshared key or certificate. If
	    the authentication is successful a secure channel is set up
	    between the two hosts, usually called a IKE security
	    association, to continue the key exchange.
	  </p></li>
<li class="listitem"><p>
	    During the second phase of the key exchange the security
	    associations for communication with the other host are set
	    up. This involves choosing the encryption algorithm to be
	    used, and generating keys that are used for encryption
	    of the communication.
	  </p></li>
<li class="listitem"><p>
	    At this point the first step is repeated again, but since
	    there are now security associations the communication can
	    proceed.
	  </p></li>
</ol></div>
<p>
        The <span class="command"><strong>racoon</strong></span> IKE daemon is included with the KAME IPsec tools,
	the sections that follow explain how to set up racoon.
      </p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950125948"></a>23.5.2. Using racoon with a preshared key</h3></div></div></div>
<p>
        As usual the first step to set up IPsec is to define security
	policies. In contrast to the manual keying example you should
	not set up security associations, because racoon will make them
	for you. We will use the same host IPs as in the example above.
	The security policy rules look like this:
      </p>
<pre class="screen">
#!/usr/sbin/setkey -f

# Flush the SAD and SPD
flush;
spdflush;

spdadd 192.168.1.1 192.168.1.169 any -P out ipsec
	esp/transport//require;

spdadd 192.168.1.169 192.168.1.1 any -P in ipsec
	esp/transport//require;
      </pre>
<p>
        Cautious souls have probably noticed that AH policies are missing
        in this example. In most situations this is no problem, ESP can
        provide authentication. But you should be aware that the authentication
        is more narrow; it does not protect information outside the ESP
        headers. But it is more efficient than encapsulating ESP packets
        in AH.
      </p>
<p>
        With the security policies set up you can configure <span class="command"><strong>racoon</strong></span>.
        Since the connection-specific information, like the authentication
        method is specified in the phase one configuration. We can use a
        general phase two configuration. It is also possible to make specific
        phase two settings for certain hosts. But generally speaking a
        general configuration will often suffice in simple setups. We
        will also add paths for the preshared key file, and certification
        directory. This is an example of 
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/racoon.conf</code></html:span> with the paths
        and a general phase two policy set up:
      </p>
<pre class="screen">
path pre_shared_key "/etc/racoon/psk.txt";
path certificate "/etc/racoon/certs";

sainfo anonymous {
{
	pfs_group 2;
	lifetime time 1 hour;
	encryption_algorithm 3des, blowfish 448, rijndael;
	authentication_algorithm hmac_sha1, hmac_md5;
	compression_algorithm deflate;
}
      </pre>
<p>
        The <em class="parameter"><code>sainfo</code></em> identifier is used to make a
        block that specifies the settings for security associations. Instead
        of setting this for a specific host, the <em class="parameter"><code>anonymous</code></em>
        parameter is used to specify that these settings should be used
        for all hosts that do not have a specific configuration. The
        <em class="parameter"><code>pfs_group</code></em> specifies which group of
        Diffie-Hellman exponentiations should be used. The different
        groups provide different lengths of base prime numbers that are
        used for the authentication process. Group 2 provides a 1024 bit
        length if you would like to use a greater length, for increased
        security, you can use another group (like 14 for a 2048 bit
        length). The <em class="parameter"><code>encryption_algorithm</code></em> specifies
        which encryption algorithms this host is willing to use for
        ESP encryption. The <em class="parameter"><code>authentication_algorithm</code></em>
        specifies the algorithm to be used for ESP Authentication or
        AH. Finally, the <em class="parameter"><code>compression_algorithm</code></em>
        is used to specify which compression algorithm should be used
        when IPcomp is specified in an association.
      </p>
<p>
        The next step is to add a phase one configuration for the key
        exchange with the other host to the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">racoon.conf</code></html:span> configuration file.
        For example:
      </p>
<pre class="screen">
remote 192.168.1.169 
{
	exchange_mode aggressive, main;
	my_identifier address;
	proposal {
		encryption_algorithm 3des;
		hash_algorithm sha1;
		authentication_method pre_shared_key;
		dh_group 2;
	}
}
      </pre>
<p>
        The <em class="parameter"><code>remote</code></em> block specifies a phase one
        configuration. The <em class="parameter"><code>exchange_mode</code></em> is
        used to configure what exchange mode should be used for
        phase. You can specify more than one exchange mode, but the
        first method is used if this host is the initiator of the
        key exchange. The <em class="parameter"><code>my_identifier</code></em> option
        specifies what identifier should be sent to the remote host.
        If this option ommitted <em class="parameter"><code>address</code></em> is used,
        which sends the IP address as the identifier. The 
        <em class="parameter"><code>proposal</code></em> block specifies parameter that
        will be proposed to the other host during phase one authentication.
        The <em class="parameter"><code>encryption_algorithm</code></em>, and
        <em class="parameter"><code>dh_group</code></em> are explained above. The
        <em class="parameter"><code>hash_algorithm</code></em> option is mandatory, and
        configures the hash algorithm that should be used. This
        can be <em class="parameter"><code>md5</code></em>, or <em class="parameter"><code>sha1</code></em>.
        The <em class="parameter"><code>authentication_method</code></em> is crucial for
        this configuration, as this parameter is used to specify that
        a preshared key should be used, with 
        <em class="parameter"><code>pre_shared_key</code></em>.
      </p>
<p>
        With racoon set up there is one thing left to do, the preshared
        key has to be added to <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/racoon/psk.txt</code></html:span>.
        The syntax is very simple, each line contains a host IP address
        and a key. These parameters are separated with a tab.
        For example:
      </p>
<pre class="screen">
192.168.1.169	somekey
      </pre>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950125884"></a>23.5.3. Activating the IPsec configuration</h3></div></div></div>
<p>
        At this point the configuration of the security policies and racoon
        is complete, and you can start to test the configuration. It is a
        good idea to start <span class="command"><strong>racoon</strong></span> with the
        <em class="parameter"><code>-F</code></em> parameter. This will run
        <span class="command"><strong>racoon</strong></span> in the foreground, making it easier to catch error
        messages. To wrap it up:
      </p>
<pre class="screen">
# <span class="command"><strong>setkey -f /etc/setkey.conf</strong></span>
# <span class="command"><strong>racoon -F</strong></span>
      </pre>
<p>
        Now that you have added the security policies to the security policy
        database, and started <span class="command"><strong>racoon</strong></span>, you can test your IPsec configuration.
        For instance, you could ping the other host to start with. The
        first time you ping the other host, this will fail:
      </p>
<pre class="screen">
$ <span class="command"><strong>ping 192.168.1.169</strong></span>
connect: Resource temporarily unavailable
      </pre>
<p>
        The reason for this is that the security associations still
        have to be set up. But the ICMP packet will trigger the key exchange.
        ping will trigger the key exchange. You can see whether the exchange
        was succesful or not by looking at the <span class="command"><strong>racoon</strong></span> log messages in
        <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var/log/messages</code></html:span>, or the output on the terminal
        if you started <span class="command"><strong>racoon</strong></span> in the foreground. A succesful key
	exhange looks like this:
      </p>
<pre class="screen">
 Apr  4 17:14:58 terrapin racoon: INFO: IPsec-SA request for 192.168.1.169 queued due to no phase1 found.
 Apr  4 17:14:58 terrapin racoon: INFO: initiate new phase 1 negotiation: 192.168.1.1[500]&lt;=&gt;192.168.1.169[500] 
 Apr  4 17:14:58 terrapin racoon: INFO: begin Aggressive mode. 
 Apr  4 17:14:58 terrapin racoon: INFO: received Vendor ID: DPD 
 Apr  4 17:14:58 terrapin racoon: NOTIFY: couldn't find the proper pskey, try to get one by the peer's address.
 Apr  4 17:14:58 terrapin racoon: INFO: ISAKMP-SA established 192.168.1.1[500]-192.168.1.169[500] spi:58c4669f762abf10:60593eb9e3dd7406
 Apr  4 17:14:59 terrapin racoon: INFO: initiate new phase 2 negotiation: 192.168.1.1[0]&lt;=&gt;192.168.1.169[0] 
 Apr  4 17:14:59 terrapin racoon: INFO: IPsec-SA established: ESP/Transport 192.168.1.169-&gt;host1ip; spi=232781799(0xddff7e7) 
 Apr  4 17:14:59 terrapin racoon: INFO: IPsec-SA established: ESP/Transport 192.168.1.1-&gt;192.168.1.169 spi=93933800(0x59950e8) 
      </pre>
<p>
        After the key exchange, you
        can verify that IPsec is set up correctly by analyzing the packets
        that go in and out with <span class="command"><strong>tcpdump</strong></span>. <span class="command"><strong>tcpdump</strong></span> is
        available in the <span class="emphasis"><em>n</em></span> disk set. Suppose that
        the outgoing connection to the other host goes through the
        <span class="emphasis"><em>eth0</em></span> interface, you can analyze the packets
        that go though the <span class="emphasis"><em>eth0</em></span> interface with
        <span class="command"><strong>tcpdump -i eth0</strong></span>. If the outgoing packets are
        encrypted with ESP, you can see this in the <span class="command"><strong>tcpdump</strong></span>
        output. For example:
      </p>
<pre class="screen">
# <span class="command"><strong>tcpdump -i eth0</strong></span>
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
17:27:50.241067 IP terrapin.taickim.net &gt; 192.168.1.169: ESP(spi=0x059950e8,seq=0x9)
17:27:50.241221 IP 192.168.1.169 &gt; terrapin.taickim.net: ESP(spi=0x0ddff7e7,seq=0x9)
      </pre>
</div>
</div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="idm950106380"></a>Chapter 24. The Internet super server</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#idm950106060">24.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950104412">24.2. Configuration</a></span></dt>
<dt><span class="sect1"><a href="#idm950098324">24.3. TCP wrappers</a></span></dt>
</dl>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950106060"></a>24.1. Introduction</h2></div></div></div>
<p>
There are two ways to offer TCP/IP services: by running server
applications standalone as a daemon or by using the Internet
super server, <span class="command"><strong>inetd</strong></span>. <span class="command"><strong>inetd</strong></span>
is a daemon which monitors a range of ports. If a client attempts
to connect to a port <span class="command"><strong>inetd</strong></span> handles the connection
and forwards the connection to the server software which handles
that kind of connection. The advantage of this approach is
that it adds an extra layer of security and it makes it easier
to log incoming connections. The disadvantage is that it is
somewhat slower than using a standalone daemon. It is thus
a good idea to run a standalone daemon on, for example, 
a heavily loaded FTP server.
</p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950104412"></a>24.2. Configuration</h2></div></div></div>
<p>
<span class="command"><strong>inetd</strong></span> can be configured using the
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/inetd.conf</code></html:span> file. Let's have a look at
an example line from <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">inetd.conf</code></html:span>:
</p>
<pre class="screen">
# File Transfer Protocol (FTP) server:
ftp     stream  tcp     nowait  root    /usr/sbin/tcpd  proftpd
</pre>
<p>
This line specifies that <span class="command"><strong>inetd</strong></span> should accept
FTP connections and pass them to <span class="command"><strong>tcpd</strong></span>. This
may seem a bit odd, because <span class="command"><strong>proftpd</strong></span> normally 
handles FTP connections. You can also specify to use <span class="command"><strong>proftpd</strong></span>
directly in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">inetd.conf</code></html:span>, but Slackware Linux normally
passes the connection to <span class="command"><strong>tcpd</strong></span>. This program
passes the connection to <span class="command"><strong>proftpd</strong></span> in turn, as specified.
<span class="command"><strong>tcpd</strong></span> is used to monitor services and to provide
host based access control.
</p>
<p>
Services can be disabled by adding the comment character (#) at
the beginning of the line. It is a good idea to disable all services
and enable services you need one at a time. After changing
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/inetd.conf</code></html:span> <span class="command"><strong>inetd</strong></span>
needs to be restarted to activate the changes. This can be done
by sending the HUP signal to the inetd process:
</p>
<pre class="screen">
# <span class="command"><strong>ps ax | grep 'inetd'</strong></span>
   64 ?        S      0:00 /usr/sbin/inetd
# <span class="command"><strong>kill -HUP 64</strong></span>
</pre>
<p>
  Or you can use the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">rc.inetd</code></html:span> initialization script to
  restart <span class="command"><strong>inetd</strong></span>:
</p>
<pre class="screen">
# <span class="command"><strong>/etc/rc.d/rc.inetd restart</strong></span>
</pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950098324"></a>24.3. TCP wrappers</h2></div></div></div>
<p>
As you can see in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/inetd.conf</code></html:span> connections for most
protocols are made through <span class="command"><strong>tcpd</strong></span>, instead of directly 
passing the connection to a service program. For example:
</p>
<pre class="screen">
# File Transfer Protocol (FTP) server:
ftp     stream  tcp     nowait  root    /usr/sbin/tcpd  proftpd
</pre>
<p>
In this example ftp connections are passed through <span class="command"><strong>tcpd</strong></span>.
<span class="command"><strong>tcpd</strong></span> logs the connection through syslog and allows for
additional checks. One of the most used features of <span class="command"><strong>tcpd</strong></span>
is host-based access control. Hosts that should be denied are controlled
via <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts.deny</code></html:span>, hosts that should be allowed
via <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts.allow</code></html:span>. Both files have one rule on
each line of the following form:
</p>
<pre class="screen">
service: hosts
</pre>
<p>
Hosts can be specified by hostname or IP address. The ALL keyword specifies
all hosts or all services.
</p>
<p>
Suppose we want to block access to all services managed through 
<span class="command"><strong>tcpd</strong></span>, except for host 
<span class="quote">“<span class="quote">trusted.example.org</span>”</span>. To do this the following
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hosts.deny</code></html:span> and <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hosts.allow</code></html:span>
files should be created.
</p>
<p>
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts.deny</code></html:span>:
</p>
<pre class="screen">
ALL: ALL
</pre>
<p>
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/hosts.allow</code></html:span>:
</p>
<pre class="screen">
ALL: trusted.example.org
</pre>
<p>
In the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hosts.deny</code></html:span> access is blocked to all (ALL)
services for all (ALL) hosts. But <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">hosts.allow</code></html:span>
specifies that all (ALL) services should be available to
<span class="quote">“<span class="quote">trusted.example.org</span>”</span>.
</p>
</div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="idm950091836"></a>Chapter 25. Apache</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#idm950091548">25.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950090932">25.2. Installation</a></span></dt>
<dt><span class="sect1"><a href="#idm950085940">25.3. User directories</a></span></dt>
<dt><span class="sect1"><a href="#idm950083380">25.4. Virtual hosts</a></span></dt>
</dl>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950091548"></a>25.1. Introduction</h2></div></div></div>
<p>
Apache is the most popular web server since April 1996. It was originally
based on NCSA httpd, and has grown into a full-featured HTTP server.
Slackware Linux currently uses the 1.3.x branch of Apache. This chapter is 
based on Apache 1.3.x. 
</p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950090932"></a>25.2. Installation</h2></div></div></div>
<p>
Apache can be installed by
adding the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">apache</code></html:span> package from the <span class="quote">“<span class="quote">n</span>”</span> disk set.
If you also want to use PHP, the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">php</code></html:span> (<span class="quote">“<span class="quote">n</span>”</span> disk set)
and <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">mysql</code></html:span> (<span class="quote">“<span class="quote">ap</span>”</span> disk set) are also required.
MySQL is required, because the precompiled PHP depends on MySQL shared 
libraries. You do not have to run MySQL itself. After installing Apache
it can be started automatically while booting the system by making
the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.httpd</code></html:span> file executable. You
can do this by executing: 
</p>
<pre class="screen">
# <span class="command"><strong>chmod a+x /etc/rc.d/rc.httpd</strong></span>
</pre>
<p>
The Apache configuration can be altered in the 
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/apache/httpd.conf</code></html:span> file. Apache can be
stopped/started/restarted every moment with the <span class="command"><strong>apachectl</strong></span>
command, and the <em class="parameter"><code>stop</code></em>, 
<em class="parameter"><code>start</code></em> and 
<em class="parameter"><code>restart</code></em> parameters. For example,
execute the following command to restart Apache:
</p>
<pre class="screen">
# <span class="command"><strong>apachectl restart</strong></span>
/usr/sbin/apachectl restart: httpd restarted
</pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950085940"></a>25.3. User directories</h2></div></div></div>
<p>
Apache provides support for so-call user directories. This means every
user gets web space in the form of <span class="emphasis"><em>http://host/~user/</em></span>. The
contents of <span class="quote">“<span class="quote">~user/</span>”</span> is stored in a subdirectory in the
home directory of the user. This directory can be specified using the
<span class="quote">“<span class="quote">UserDir</span>”</span> option in <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">httpd.conf</code></html:span>, for
example:
</p>
<pre class="screen">
UserDir public_html
</pre>
<p>
This specifies that the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">public_html</code></html:span> directory should
be used for storing the web pages. For example, the web pages at URL 
<span class="emphasis"><em>http://host/~snail/</em></span> are stored in 
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/home/snail/public_html</code></html:span>.
</p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950083380"></a>25.4. Virtual hosts</h2></div></div></div>
<p>
The default documentroot for Apache under Slackware Linux is
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var/www/htdocs</code></html:span>. Without using virtual hosts
every client connecting to the Apache server will receive the
website in this directory. So, if we have two hostnames pointing
to the server, <span class="quote">“<span class="quote">www.example.org</span>”</span> and 
<span class="quote">“<span class="quote">forum.example.org</span>”</span>, both will display the same website.
You can make separate sites for different hostnames by using
virtual hosts.
</p>
<p>
In this example we are going to look how you can make two virtual
hosts, one for <span class="quote">“<span class="quote">www.example.org</span>”</span>, with the documentroot
<html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var/www/htdocs-www</code></html:span>, and <span class="quote">“<span class="quote">forum.example.org</span>”</span>,
with the documentroot <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/var/www/htdocs-forum</code></html:span>. First
of all we have to specify which IP addresses Apache should listen to.
Somewhere in the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/apache/httpd.conf</code></html:span> configuration
file you will find the following line:
</p>
<pre class="screen">
#NameVirtualHost *:80
</pre>
<p>
This line has to be commented out to use name-based virtual hosts.
Remove the comment character
(#) and change the parameter to <span class="quote">“<span class="quote">BindAddress IP:port</span>”</span>, or
<span class="quote">“<span class="quote">BindAddress *:port</span>”</span> if you want Apache to bind to all IP addresses
the host has. Suppose we want to provide virtual hosts for IP address 
192.168.1.201 port 80 (the default Apache port),
we would change the line to:
</p>
<pre class="screen">
NameVirtualHost 192.168.1.201:80
</pre>
<p>
Somewhere below the NameVirtualHost line you can find a commented example
of a virtualhost:
</p>
<pre class="screen">
#&lt;VirtualHost *:80&gt;
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#&lt;/VirtualHost&gt;
</pre>
<p>
You can use this example as a guideline. For example, if we want to use
all the default values, and we want to write the logs for both virtual
hosts to the default Apache logs, we would add these lines:
</p>
<pre class="screen">
&lt;VirtualHost 192.168.1.201:80&gt;
	DocumentRoot /var/www/htdocs-www
	ServerName www.example.org
&lt;/VirtualHost&gt;

&lt;VirtualHost 192.168.1.201:80&gt;
	DocumentRoot /var/www/htdocs-forum
	ServerName forum.example.org
&lt;/VirtualHost&gt;
</pre>
</div>
</div>
    <div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="idm950077628"></a>Chapter 26. BIND</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="#idm950077340">26.1. Introduction</a></span></dt>
<dt><span class="sect1"><a href="#idm950069932">26.2. Making a caching nameserver</a></span></dt>
</dl>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950077340"></a>26.1. Introduction</h2></div></div></div>
<p>
The domain name system (<acronym class="acronym">DNS</acronym>) is used to convert
human-friendly host names (for example www.slackware.com) to IP
addresses. <acronym class="acronym">BIND</acronym> (Berkeley Internet Name Domain) is
the most widely used DNS daemon, and will be covered in this chapter.
</p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950076300"></a>26.1.1. Delegation</h3></div></div></div>
<p>
One of the main features is that DNS requests can be delegated. For example,
suppose that you own the <span class="quote">“<span class="quote">linuxcorp.com</span>”</span> domain. You can provide
the authorized nameservers for this domain, you nameservers are authoritative
for the <span class="quote">“<span class="quote">linuxcorp.com</span>”</span>. Suppose that there are different
branches within your company, and you want to give each branch authority
over their own zone, that is no problem with DNS. You can delegate DNS
for e.g. <span class="quote">“<span class="quote">sales.linuxcorp.com</span>”</span> to another nameserver within
the DNS configuration for the <span class="quote">“<span class="quote">linuxcorp.com</span>”</span> zone.
</p>
<p>
The DNS system has so-called root servers, which delegate the DNS for
millions of domain names and extensions (for example, country specific
extensions, like <span class="quote">“<span class="quote">.nl</span>”</span> or <span class="quote">“<span class="quote">.uk</span>”</span>) to authorized
DNS servers. This system allows a branched tree of delegation, which is
very flexible, and distributes DNS traffic.
</p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950073644"></a>26.1.2. DNS records types</h3></div></div></div>
<p>
The following types are common DNS record types:
</p>
<div class="table">
<a name="idm950073244"></a><p class="title"><b>Table 26.1. DNS records</b></p>
<div class="table-contents"><table summary="DNS records" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Prefix</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td>A</td>
<td>An A record points to an IPv4 IP address.</td>
</tr>
<tr>
<td>AAAA</td>
<td>An AAAA record points to an IPv6 IP address.</td>
</tr>
<tr>
<td>CNAME</td>
<td>A CNAME record points to another DNS entry.</td>
</tr>
<tr>
<td>MX</td>
<td>A MX record specifies which should handle mail for 
the domain.</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm950070596"></a>26.1.3. Masters and slaves</h3></div></div></div>
<p>
Two kinds of nameservers can be provided for a domain name: a master and
slaves. The master server DNS records are authoritative. Slave servers download
their DNS record from the master servers. Using slave servers besides a
master server is recommended for high availability and can be used for
load-balancing.
</p>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idm950069932"></a>26.2. Making a caching nameserver</h2></div></div></div>
<p>
A caching nameserver provides DNS services for a machine or a network,
but does not provide DNS for a domain. That means it can only be used
to convert hostnames to IP addresses. Setting up a nameserver with
Slackware Linux is fairly easy, because BIND is configured as a
caching nameserver by default. Enabling the caching nameserver takes
just two steps: you have to install BIND and alter the initialization
scripts. BIND can be installed by adding the bind package from
the <span class="quote">“<span class="quote">n</span>”</span> disk set. After that bind can be started by executing the
<span class="command"><strong>named</strong></span> command. If want to start BIND by
default, make the <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/rc.d/rc.bind</code></html:span> file executable.
This can be done by executing the following command as root:
</p>
<pre class="screen">
# <span class="command"><strong>chmod a+x /etc/rc.d/rc.bind</strong></span>
</pre>
<p>
If you want to use the nameserver on the machine that runs BIND,
you also have to alter <html:span xmlns:html="http://www.w3.org/1999/xhtml" class="filename"><code class="filename">/etc/resolv.conf</code></html:span>.
</p>
</div>
</div>
  </div>



</div></body>
</html>
